#python-discussion
1 messages · Page 223 of 1
omg now i know how it works from pathlib import Path
current_folder = Path('.')
for file_or_dir in current_folder.iterdir():
print(file_or_dir)
i thought that i need to put in current_folder('') like then ame of the folder not just a plain dot i thoguht the dot was a place holder
you can put the name of a folder if you want
i tried it gave me errors
. is always the current folder
you likely needed to use a raw string
really common issue with windows path strings
on windows you have to use a raw string
whats a raw string 
are you familair with special characters like \n?
yes
r'C:\Users\eivl\Documents\projects\new_project'
well what if you had a path that had that in it? folder\new_stuff\november\data.txt
thx that worked
C:\Users\liebe\OneDrive\programming.idea
C:\Users\liebe\OneDrive\programming\apis
C:\Users\liebe\OneDrive\programming\bank_system
C:\Users\liebe\OneDrive\programming\bitcoin
C:\Users\liebe\OneDrive\programming\calc
C:\Users\liebe\OneDrive\programming\compre
C:\Users\liebe\OneDrive\programming\learning
C:\Users\liebe\OneDrive\programming\ls_project
C:\Users\liebe\OneDrive\programming\password_checker_manager
C:\Users\liebe\OneDrive\programming\pdf
C:\Users\liebe\OneDrive\programming\PyCharmMiscProject
C:\Users\liebe\OneDrive\programming\TicTacToe
listed this
python will get confused with the \n here in the path. There's many other special characters too. If we want python to treat everything here as literal text, we need the raw string. It basically tells python to ignore all the special sequences
if im supposed to use \n why did r'' work
I never said to use \n
oh lol
I said that things like \n can cause issues
just an example
its odd why did r'' fix the problem i only ever use that for regex
!e
print('1hello\nworld')
print(r'2hello\nworld')
:white_check_mark: Your 3.14 eval job has completed with return code 0.
001 | 1hello
002 | world
003 | 2hello\nworld
it's the same reason
look at the difference between these two prints
One of them sees \n as a newline. One of them sees it as the literal text \n
oh wow thanks for teaching me smth new didnt realize that
thats prob gonna be useful for the future t
yes, it's really helpful for paths/regex
C:\Users\liebe\OneDrive\programming.idea
C:\Users\liebe\OneDrive\programming\apis
C:\Users\liebe\OneDrive\programming\bank_system
C:\Users\liebe\OneDrive\programming\bitcoin
C:\Users\liebe\OneDrive\programming\calc
C:\Users\liebe\OneDrive\programming\compre
C:\Users\liebe\OneDrive\programming\learning
C:\Users\liebe\OneDrive\programming\ls_project
C:\Users\liebe\OneDrive\programming\password_checker_manager
C:\Users\liebe\OneDrive\programming\pdf
C:\Users\liebe\OneDrive\programming\PyCharmMiscProject
C:\Users\liebe\OneDrive\programming\TicTacToe instead of this getting printed any way for my to just print the project ideas
regex i knew already didnt know we use it on paths but hey first time using paths here so ye xd
what do you mean project ideas?
then you might not have fully understood why it was being used for regex strings
ye i guess i didnt
so you want just the folder names without the full paths?
i didnt wonder enough for it
yes
file.name will print only the name
path objects have properties that allow you to access specific information
i assumed it would be .name and i was right
yeah, file_or_dir.name
😎
for files, this gives the full filename like foo.txt
beat u to it eivl xd
if you just want foo, it would be .stem
and if you just wanted the extension, it's .suffix
TIL about the with_stem method. Super useful
stem and name give me same result
it will for folders
many with things!
not for files though
suffix gives me nothing
yeah I saw, they're really nifty
folders don't have extensions
.stem =
.idea
apis
bank_system
bitcoin
calc
compre
learning
ls_project
password_checker_manager
pdf
PyCharmMiscProject
TicTacToe
.name =.idea
apis
bank_system
bitcoin
calc
compre
learning
ls_project
password_checker_manager
pdf
PyCharmMiscProject
TicTacToe
with_suffix is the new one i think
there isnt a diff here right?
or maybe it was segments
stem will be the same for folders and files
it only starts to make a difference when looking at files
When it comes to any sort of audio/voice input. Webrtcvad is basically a requirement right?
no, when dealing with file names
what do u mean when looking into the names?
Over network?
a folder can contain files and folders
My dumb ass has been using chatgpt to help guide me through what to use to build a voice assistant, and at first it was telling me this "np.linalg" which I guess is just for sound detection, not real voice detection
For transcribing speech audio
if you print .name for a file, you get the full name, including extension
I'm saying if you want a specific part of the filename, like the part before the extension or just the extension, you need .stem or .suffix
file_or_dir.stat() will also be usefull
faster Whisper keeps giving me phantom transcriptions using just np.linalg
I think there are some python libs for thid
Oh like this
.stem
Attachments
Desktop
desktop
Documents
Pictures
programming
.name
Attachments
Desktop
desktop.ini
Documents
Pictures
programming the.inl goes poof
I just set this up recently to get some file information in my GUI 🙂
os.stat_result(st_mode=16895, st_ino=4222124650821109, st_dev=17741944189098916607, st_nlink=1, st_uid=0, st_gid=0, st_size=4096, st_atime=1769588559, st_mtime=1769099318, st_ctime=1766741852)
why would i need smth like this
yeah, i use it as well
Lets me compare creation/modified time
you dont have to use os at all, you can just use pathlib
that's the return of Path.stat
ahh.. good.. i missed that
just want to go to the next step and making sure im on right track current_folder = Path(r'C:\Users\liebe\OneDrive\programming')
for file_or_dir in current_folder.iterdir():
file = file_or_dir
print(file)
from here i should like append my file to a list then go through the list and open each file to see whats inside of it?
it's entirely up to you, but there's definitely no need to do file = file_or_dir
ls does not look inside the file content
ls lists the contents of a directory
it just shows you file and folder stats on that line
ik i was checking smth im deleting that part
Why not open it in the current loop
but because i have smth like C:\Users\liebe\OneDrive\programming\TicTacToe cant i just list hwats inside the tictactoe
i could do that?
sure, how would adding it to a list first be any different?
yes
this is where you would have to implement cd
"change directory"
thought it wouldnt work xd so i was gonna add it to a list this is much better
for file_or_dir in current_folder.iterdir():
if file_or_dir.is_dir():
for file in file_or_dir.iterdir():
print(file) got it
at this point, you might as well just use rglob
How about recursion... I never used recursive stuff
that's exactly what rglob is. The "r" stands for "recursive"
why should i use recursion
I am very pythonic, never doubt me
traversing file trees is a great use-case for recursion
you have function that says "look inside the folder". The recursive bit is "if you find a folder inside that folder, look inside that too"
like the problem is like recurrence relation.
Like the x is related to x+1
Dir1 is parent of dir2
is rglobe a function with module?
it's a method of pathlib.Path objects
ok im gonna look for it and il try to do this part bymyself
so i wanna get rid
for file in file_or_dir.iterdir():
print(file) and use rglobe?
I had already showed an example of it above
instead of *.png you can just do * to search for everything
holy that prints alot
it's every file and every folder
all i want is the stuff inside the file not the stuff in file in file in file
for file in file_or_dir.iterdir():
print(file) this gave me it
gave me all the files that are in that file and done
if you want to choose the next file to look in, you need to implement a cd function
for file_or_dir in current_folder.iterdir():
if file_or_dir.is_dir():
for file in file_or_dir.iterdir():
print(file.name)
this worked
that's how navigating directories in a terminal usually works
ls to list the contents of your current folder. cd to choose which folder to move into
the recursion gave me everything i just needed the names inside the file not name in name in name
so if I do ls and get back
dir_a
dir_b
dir_c
This does one level of search. In recursion it goes untill base case thats no more sub folders
if I want to know what's inside dir_b, I would do cd dir_b
i dont want that
Do you only need a certain file type?
it's not clear what you want then
i got to my folder with my project i open each project to see whats inside
for file_or_dir in current_folder.iterdir():
if file_or_dir.is_dir():
for file in file_or_dir.iterdir():
print(file)
this does exactly that
that does the same as rglob
recursions continues but at that point i dont need that info
recursions prints everything for example
project data has main.py venv. idea. recursion continues it goes inside of those files aswell i dont want that
C:\Users\liebe\OneDrive\programming\TicTacToe.idea
C:\Users\liebe\OneDrive\programming\TicTacToe.venv
C:\Users\liebe\OneDrive\programming\TicTacToe\games.py i like this but recursion goes further
Explain exactly what you want. Make sure you're clear about talking about files and folders
my folder is programming my folders(projects) in programming are what i want to go inside to see what folders are in them (main.py etc) i dont want to continue after that
recursion continues till the end
but which one do you want to go inside specifically?
directory traversal does not open files
im going into my project folders
why that one?
C:\Users\liebe\OneDrive\programming\TicTacToe.idea
C:\Users\liebe\OneDrive\programming\TicTacToe.venv
C:\Users\liebe\OneDrive\programming\TicTacToe\games.py my code gives me this recurions continues
C:\Users\liebe\OneDrive\programming\TicTacToe\games.py/etc/etc/etc/etc till it cant no more
uh? i dont get the question
how do you want to decide which subfolder to look in?
il figure that out soon but rglobe prints to much
Something like this? [Path(p) for p in glob.glob("**/*") if Path(p).is_file()]?
did you read what I said about cd above?
cd decides which folder to open yes ik
whats the two asterik before the slah
Both wildcard?
folder
glob syntax
ok so you need to get input to choose which folder to move into
C:\Users\liebe\OneDrive\programming\TicTacToe.venv\Lib\site-packages\charset_normalizer-3.4.4.dist-info\licenses\LICENSE
C:\Users\liebe\OneDrive\programming\TicTacToe.venv\Lib\site-packages\charset_normalizer\cli_init_.py
C:\Users\liebe\OneDrive\programming\TicTacToe.venv\Lib\site-packages\charset_normalizer\cli_main_.py
C:\Users\liebe\OneDrive\programming\TicTacToe.venv\Lib\site-packages\charset_normalizer\cli_pycache_ just expkaining what i mean about inf o idont want idc about whats in my .venv i just wanted to see if i have a .venv .main etc in my folder idc about the other stuff
ye thats what im doing next
Hmm but what are you trying to achieve just learning??
that's what you need to do now
then you can easily navigate your folders with code
it's quite simple to set up
input = input("Enter a file name: ")
current_folder = Path(fr'C:\Users\liebe\OneDrive\programming{input}')
for file_or_dir in current_folder.iterdir():
print(file_or_dir)
im dumb i dont need an extra loop
😂
remember you can use / for path objects
(also don't use input as a variable)
ye ik i was gonna change it
just wanted to see if it worksbut hey now i made it work time to clean it up
also make sure you're clear about the difference between a file and folder
I think a lot of your questions were confusing because you were mixing them up
i know im sorry for confusing u xd
location = input("Enter a folder name: ")
current_folder = Path('.') / location
for contents in current_folder.iterdir():
print(contents)
/ is the best 🙂
it was confusing me that there is folders in folders so i kept confusing u xd
Tell me how to have txt file in structured format? When we have data in tabular form
Means what to do to have structured txt file
the structure will depend on what you're trying to do
Use json
location = input("Enter a folder name: ")
current_folder = Path(r'C:\Users\liebe\OneDrive\programming') / location
for file_or_dir in current_folder.iterdir():
print(file_or_dir.name) this code is only 5 lines its not even long or smth
Actually I have convert PDFs to txt files
now i gotta add when it was created and all but im getting the hang of it now so w?
you're most of the way there to cd now
I already use json still
does everybody use ruff as their linter now? like i mean almost everybody
like how people have moved to using uv
is ruff "the" linter for python during this time
well didnt i just do cd with the input?
i did cd ls_project then ls
someone told me that it is but ive never thought of it that way
well hopefully eventually you'll ask the user if they want to ls or cd
ive only thought of it as another linter available, which is popular right now
oh ye ofcourse i should do that
so you need to parse if they typed cd and what the following dir name is
what should i print if they only want to do cd
Like i use vscode. I think linter comes with microsoft extension
it doesn't need to print anything
you just need to keep track of the "current folder"
that's pylance, and by extension pyright
i too use pyright as my linter, i used to use basedpyright
cd just moves to a new "current folder"
yes exactly
Ohk, i also make use of black formatter
ye i could do that
and cd .. means "go up 1 folder"
I think ruff does that too?
ruff does yeah, it also sorts the imports like isort does
Actually I made chatbot and store that txt files in backend
i think imma first do smth like this tho
Mode LastWriteTime Length Name
d----- 1/28/2026 10:41 AM .idea
d----- 1/28/2026 10:11 AM .venv
-a---- 1/28/2026 11:28 AM 267 main.py
you can get the parent folder using .parent in pathlib
I would get the base navigation working first. Then you can focus on formatting/style.
.parent folder would be programming right?
location = input("Enter a folder name: ")
current_folder = Path(r'C:\Users\liebe\OneDrive\programming') / location
ok so keep track of whether user wants cd and ls got it il do that next
it depends on what your current folder is. If you've already cd a few times, then .. should just go up 1 folder
!cleanban 1465834643302514760 ad spam
:incoming_envelope: :ok_hand: applied ban to @charred bison permanently.
darn, i was hoping i could give him some money because he promised me more money in return
sorry the offer was only valid for 5 seconds
damn... job offers are insane nowadays
he was banned so no one else could claim it
baba is scam
scam is win
I was thinking of making a flake8 plugin that warns about suspicious/bad usage of re, but I feel like nobody is going to use it, as people are moving away from flake8
I don't think ruff is planning to add plugin support any time soon
What are suspicious/bad usages of re?
C:\Users\liebe\OneDrive\programming\ls_project\main.py' fosh how do i prevent the double \ else:
current_folder = current_folder / input_cd_ls
LIke using /d for [0-9]
you'll need to do a bit of parsing. If they typed cd other_folder, you need to split the text to get the name of the folder they want to cd into
0|1|2|3|4|5|6|7|8|9 is bad
I think it has to do with numerals in other languages?
atm im just doing the inputs with cd like main.py the thing is im getting erorr cause its doing this 'C:\Users\liebe\OneDrive\programming\ls_project\main.py' double \
you can't cd into a file
cd is "change directory"
why isnt it chdir
depends on os 🤷
windows doesn't have ls
it's dir
nm powershell has ls, just not terminal
For example:
- using modifiers that you might be used to using but are probably wrong (e.g.
\dand$) - likely typos such as
{3, 5}(which is the string{3, 5}literally, you probably meant{3,5}), or typoing(?<!negative lookahead)as(?!<negative lookahead) - using
^...$or equivalent withre.match/re.searchwhen you should just usere.fullmatch
current_folder = current_folder / input_cd_ls so this cant work at all?
Read what I wrote
2 things. You need to parse the cd to get the actual destination, and you also can't cd into a file
oh if i cant cd into a file then how do i do + 1 to the folder like u said earlier
what do umean by parse
Hey guys, I had a small doubt.
I was working on a project and I'm trying to import a file into all of my other files. But its keeps on saying that they can't find the file.
GPTs saying that I must include an empty __init _ _.py file into all the directories to make it work.
Can anyone explain why?
you have to verify that the destination is a valid folder and not a file
parse means taking the information and getting usable data from it
if they type cd other_folder then the goal is to cd into other_folder
if you just take their input directly then you're trying to cd into a folder named "cd other_folder"
That was needed in older versions of python.
ok il figure this out later gotta join a zoom for smth
Adding that makes your folder a package
it's no longer necessary to import from it though. Only if you want to import the package name itself
\d matches a lot of decimal digits that are not 0123456789 (like ௫), which is probably not intentional
What you need now is probably an import relative to the root of your project and running it with -m
i see
ye so for the first time they cd it works the 2nd time not so much sop il figure it out later
This is the current file structure:
Project_root/Directory_1/ - containing python files tryin to import config file
Project_root/config/settings.py
so do I not need the __init.py file then?
you only need the __init__ if you plan on importing the folder itself. When you do that, it will run the code inside __init__.py
Import as config.settings
And then run with py -m Directory_1/filename.py
Why not keep the common file in something called util in root and then i think all other files can import it
Alright, Thanks for the help.
Why the -m flag
is there a blog demoing these
I see we use it with venv too
not sure what you mean, but I recently made this https://decorator-factory.github.io/python-re-quiz/
I thought I was doing pretty good until I got to about #7
yeah, you gotta be sober for #6 and #7
Hey could anyone help me I can't import a module into mu
I already failed at 4 😔
i didnt even pass 1...
It ended up being more of a troll quiz than educational quiz. Except maybe for #3, hopefully people will phase out $ in new regexes
as a former Perl programmer, that was the expected behavior for me, and I didn't know about \A and \Z
I haven't used mu but could you elaborate on what issue you're running into? Maybe open a help thread for this
but I'll probably remember to use re.fullmatch in future so 👍
the name of re.match is definitely one of my pet peeves of all time
I always write re.match when I mean re.search (Perl, again, probably)
in fact I did that yesterday
(but I still got the question right, somehow)
But it matches
Yeah wait
It's open @swift sparrow
It is specifically a prefix match, so re.match("foo", "foobar") produces a match, but re.match("foo", "a foo") doesn't
it is occasionally useful, but it's probably not what you want
Ok, I've replied there
it can match any decimal Unicode digit, such as ² or 🯹
It doesn't match ²
It seems to match charcters from the decimal number category in unicode
"²".isdigit() is True but "²".isdecimal() is false...
Can we crack a exo file without the key?
It's always what you wnat when parsing.
!rule 5
5. Do not provide or request help on projects that may violate terms of service, or that may be deemed inappropriate, malicious, or illegal.
I am just asking if it's possible
no
And i'm just pointing you to the rules saying we don't talk about that stuff here
Yes, parsing text in chunks (without lexing it first) is probably the use case for it
It is..
it's not possible
Though in that case you probably want re.Pattern.match, which accepts a starting position
helu
guys how do u split a number with decimals?
like if input = 12.75
how to split 12.75 to 12, 75
why do you want this?
for an assignment
Do you have to use math, or can you use string operations
I want to keep dividing a number, let's say 75, while it is > 0
which results in:
75.0
37.5
18.75
9.375
4.6875
2.34375
1.171875
0.5859375
But, I want to make it to where it divides to 37.5
ignores the .5 in 37.5
divides 37
into 18.5
and same process repeats
until it meets 0.5
string operations?
!rule 6 @hoary scaffold Whatever it is, you can't advertise on this server.
So you don't want to use the fractional part, you just want to discard it?
You can use math.floor then
You can call int() on a number to just get the integer part
@mods i — dammit fix I’m tired, at least let me get the words out so I can feel useful
:3
You see, I'm on my 4th week of Python Class. Our professor hasn't taught us the math.floor thing, so I'd like to use beginner methods
threatening other members... mods ban this person
Yes but, I also want to have a separate function for the decimal
if 75 / 2 = 37.5
split 37.5 into 37 and 0.5
if theres a 0.5, or a decimal, print 1
if theres no "." or decimals, print 0
divide 37 / 2 > 18 / 2 > 9 /2 etc.
judging from that maybe u know what I'm trying to do
If you always start with an integers, you can use the // (floor division) operator. 37 // 2 is 18
As Grote said, you can also call int() on a float, which will truncate it (it is different from "flooring" for negative numbers, probably not relevant for you).
so I'd like to ask how do I do all of those functions
You probably want to use % (modulo) to figure out if a number is divisible by 2
I see, can u give me an example of that?
That should've definitely been part of your course. Can you show the assignment text perhaps?
give me a sec
- Write a code that converts a decimal number to any number system.
- Write a code that converts any number system to DECIMAL.
Most specifically to Binary(Base 2), Octal(Base 8), Hexadecimal(Base 16).
Without using built-in functions like bin, oct, dec, hex
and must be able to convert numbers with decimals like 75.25 or 101.101
I told them to check out my profile so they would know I'm a developer; I wasn't advertising anything.
For converting between systems, you can use // and %. Those are very likely explained something in your course, if they weren't, that's a big oversight (you can't reasonably this problem without them)
But you can check out https://docs.python.org/3/tutorial/introduction.html#numbers for some examples
does it have % modulo examples
Converting fractional numbers between bases is pretty challenging. For example, what's the expected answer if you need to convert the decimal 0.1 to binary?
I think I'll make it to where 1 is the minimum
For example, the number of deer remaining after deer season is called the remaindeer.
because I'm not going to dive into something too complex for a student on his 4th week of python
What's the expected answer if you need to convert 1.1 in decimal to binary?
Jarvis send this guy to the moon
That's going to be a repeated fraction in binary is what I'm saying
hmmm
1.(00011) specifically
we're tasked to also limit it to 4 decimal places
like converting 1.1 to binary will be 1.0001
@spice hill so quick question, if it is currently 7:08pm, and the deadline is in 12 hours, do u think it is still possible for me to finish this entire assignment
Make it work with just integers first. Then see if you can figure something out with fractions
mk
Simeone gave me brainrot
is there a python equivalent or analogy for struct in C?
I'm trying to follow something but it's in C and I don't really know it
is it like a dataclass?
yeah, a dataclass is close enough
alright, thanks
convert decimal to binary perhaps?
yes
Guys if anyone here has an arduino or something similar is it reasonable to buy a cheaper clone first to learn
check if it's even or odd and divide by 2 taking the int
I already made this
DeciBin = float(input("Enter a Decimal: "))
print("Decimal to Binary Conversion")
while DeciBin > 0:
DeciBin = DeciBin // 2
if DeciBin % 2 == 0:
print("0")
else:
print("1")
but it keeps infinitely printing 0
if I put 75
guys I really need help
assignment is due soon
functionality wise , the clone works the same as the original arduino board
the only time i used an original board is in our university , but mostly people just buy the 4 USD clones and use those
what would be the output of 75.25
with all the respect its not my assignment, we're trying to help u
i havent gotten to that part yet
yoo anyone want to rate my projects??
im focusing on integers first
Ok thank you very much
next time maybe dont wait untill the very last hour to do the assignment 💀
Yes, and I'd be really happy if theres someone here that can stick with me until its done
or maybe help me with some bugs
open a help thread, hard to find someone to stick with you for an hour or two and keep up with the whole conversation
with the help thread , anyone can pop in , read the history and be up to speed with whats going on
ok
that code seems valid more or less
HELLOOOO
hi 👋
the while loop needs indentation but it looks valid
changed it to int, doesn't infinitely print 0 anymore
what do you want from a review ?
problem is it cant handle decimals anymore
idk tips or smth
just do this:
while DeciBin > 0:
if DeciBin % 2 == 0:
print("0")
else:
print("1")
DeciBin = DeciBin // 2
instead
the division afterwards
make a thread in #1035199133436354600 and put the code review tag
u can open a help thread as well
but my code is not that like its a small slot machine shi like no one is gonna review this
well if you change your mind and want someone to take a look , you know what to do : )
hi
lmao
hello
"not that": what did you think the code review tag is for?
did i say something funny ?
idk
for reviewing some advance codes
so you saw my message and just randomly decided to laugh , weird 
🙂
laughing is healthy
it;s for reviewing any code
ohh alr
Indeed, advanced code is less likely to recieve reviews. People are going to look at it and go, "Nope!"
Whereas simpler, more conceptually accessible code is liable to have more takers.
yea also if u focus the thread on a specific section it's better
I opened one
on the specific problem you're facing, what lines of code it likely lies in
alright
.
To review code, first you have to read it, then you have to understand it
The harder it is to read or understand code, the harder it is to review it, and the less likely someone will dedicate the time
...i would kinda just comment that it's unreadable as a review
i guess saying it's unreadable isnt really a review
Such a Magnificent Statement.
I think it is
"This code is unreadable, I cannot validate it. Code in our codebases has to be readable, rejected"
In nicer words
Usually I just point to spots that are gnarly and ask them to explain it. They can't, and, well.. that's a rejection
comments should rarely be used, but doesnt mean you shouldnt use them.
now docs on the other hand
comments should generally explain the why not the how.
and in genrally if you need to explain the why the code could likely be written more clearly instead
you should write comments to explain complicated things, or why you did something.
ideally the code is understandable without them, but often that is not the case.
those arent comments, and you should 100% write those
docstrings are good, write them.
they help you think about what the function does
yeaa ok
this video has some good takes on it with examples of pros and cons: https://youtu.be/Bf7vDBBOBUA
Why you shouldn't write comments in your code (write documentation)
Access to code examples, discord, song names and more at https://www.patreon.com/codeaesthetic
References:
https://www.commitstrip.com/en/2016/08/25/a-very-comprehensive-and-precise-spec/?
(and ofc the title is a bit clickbaity )
This is an excellent video.
it's funny that it puts math as an "exception"
Admittedly, that's something I'm terrible at, commenting or docstrings. It does make it harder to resume a project after a break
This changes with the type of code you are doing
I mean I think it applies pretty generally, ofc if the concept in the code are very advanced or esoteric then yeah some comments could help.
or ofc if you are a beginner and still learning leaving yourself comments help
(the trap is getting into the habbit of always writing that kinda explanatory comments once you dont need them anymore )
If you start using variables for a ton of things that aren't necessarily needed in embedded programming for example what he says in the beginning of the video can become an issue
Good naming can help a lot with code readability
really? does using a variable actually bloat the compiled code? that feels wrong
I mean 99% of The Time , It's better having Magic Values and Have a Constants File.
Well variables use memory which you are limited on, depending on how big your project is & what hardware you are using this can be the difference between running your script or maxing out
I think the operative part there was 'embedded', where the constraints are more significant
right, but shouldnt most compilers elevate variables to registers if they can
I don't think having 50 or 60 variables like these would be a big deal for memory.
If it's a local variable, if something is used multiple times over different functions it wont
on something like an arduino, you have about 2KB to work with
or less depending on the model
and the alternative is re-calculating it every time instead?
is there an ipc guide thats a video rather than documentation?
Is it really this less?
trading space with time is always good
yes, in embedded yeah
I remember learning in C that the stack is ≈ 8 Mb
it's also an issue at larger scales
Idk About Python
if your working on arduino i dont think that ever a problem fr
And Heap is Much Bigger than That.
e.g. i work on regular computers and compute clusters, but the stuff i need to move around is petabytes large
It depends on what you use or are trying to do I guess.
Some things you can just run inside of your function you are trying to do without needing to grab variables from other functions
so sometimes it's simply better to compute things on the fly, repeatedly. slower, but otherwise impossible
and naturally that complicates the logic. even worse when generating on the fly involves a lot of math. no amount of clear code and nice variable names will help if the math is involved
otherwise math papers and books would be just equations, no text
I've uploaded super simple programs to an Arduino I got laying around here somewhere and it filled out so easy 
give me the simple programs repostory fr
ah yeah, to make matters worse, the variable space is also shared with the code space
long code means even less space for your variables
My ESP for school projects that are rather simple I've also gotten rather close to maxing it out on space, which isn't anything special on it's own
I don't have that saved I was just reading out an US sensor with a state machine
xd
i've maxed it out doing audio processing
say you wanna do some FFTs directly on the microcontroller. you reap benefits by FFTing more samples at a time because of the NlogN complexity
but only if you work with powers of 2. grabbing 1024 samples at a time will already give you something to think about on an arduino, whereas your computer can churn through vectors with millions of elements
I guess library's might take a chunk as well
, never really thought about that
Some library's you use in embedded for simple stuff are gigantic because it supports a wide range of hardware
This guy is great
two things i dont like.
one - why would anyone do message* receive_message();? it's obvious that you're supposed to do message *receive_message();
second - math is not r eally an exception. this whole idea breaks apart when you do anything that's just slightly too complex
i definitely agree that using intermediate variables makes the code easier to understand.
on the math thing, right, but most complex stuff is still understandable by understanding the code, but math often wont make sense even if you understand what the code is doing, "but why are we using this forumla"
the other thing that he didnt talk about that comments are good for is to explain what a section of the code does
if you have a long function, it helps to break it down with comments to explain what each section is doing
you could technically extract it to multiple different functions, but especially if youre involving a lot of variables in each step, it doesnt add a lot of readability
(I often tend to use log calls to denoate sections)
Is there someone who use CodeSnack ide here
it's the same thing really
a log call is just a comment you print somewhere 🙂
but also you can in general split up a function if you are smart about it, ofc that does depend on what its doing
What ide do you use
i use multiple different IDEs. i use neovim, vscode, and pycharm
I only use CodeSnack
idk what codesnack is
heyy, i know this question is probably asked every ten minutes but how did yall learn python and do you recommend the way u chose
it's not always easy
if your section of code that you extract to a function uses one or two variables, that's acceptable. but if that section is involved and requires access to like 5 different variables, it becomes more convoluted to split the function than keeping it in
but then maybe you could group that data into a dataclass and create methods on it
It is ide for iPad and stuff i want autosuggestion but i idk how I can have that
I learned Python as my maybe fourth or fifth programming language in a very haphazard way while I was studying at uni. No, I would definitely not recommend it.
you could, but then youre paying the cost with more abstractions, simply for the benefit of having a separate function
that might not be worth it. now instead of one codeblock, you have three
example you type prin then it suggests print
Hi. I'm new to Python (only a few weeks in, and haven't been practicing often) and I feel like I can't do the problems assigned to my class. Where can I find a video series about python and maybe a website for challenges?
ill be honest programming on an ipad sounds like a terrible experience
- Automate the Boring Stuff is a really good book for complete beginners and it's free to read online.
- If you prefer to watch video tutorials Corey Schafer's playlist is also really good.
- I also recommend Harvard’s free online course CS50P: Introduction to Programming with Python.
- Python Programming MOOC 2025 is an alternative online course with lots of integrated practice problems you can do directly in the browser.
That’s only thing i have
yeah, and its always gonna be hard to discuss this stuff in the abstract, because there will always be a case where it wont work cleanly etc.
Thank you for the detailed response, you must get asked that a lot
i am currently reading book called "grokking algorithms"
Multiple times a day, yes.
Brocode is definitely the goat
Search the first phrase up xD
'252 results'
sometimes having one big function is the cleanest way to solve the problem
and in that case, comments can be pretty useful
I've definitely ignored a few RET504 warnings because I wanted the names there
yeah especially if the last line isnt just cartoon example bar = 1; return bar. if it's some kind of calculation or the result of a chained operation... might as well clarify
but then shouldnt also the function doc string already have specified/explained what the return value is?
🤔 yes and no
i mean yes it explains what youre supposed to be getting back, but no it doesnt explain what the last calculation means
I think it's better to take statements like "don't write comments" as ideas that are good to be aware of and keep in the back of your head as you write code. There's a valid concept in there, even if it doesn't necessarily apply in all situations.
what do you mean by "haphazard way"
As in, I didn't study it in a structured and consistent way, I just looked stuff up here and there when I needed it, and I sometimes there would be months passing by without me even using Python. That's definitely not something I'd recommend for someone who just started learning their first programming language.
i agree with a lot of the cases he presented
you can, quite often, resolve the need for a comment with variable extracts, reshuffling the code a little, which is better than having a comment
it's just that you can also go overboard, and try to remove comments by twisting the code in shapes that dont actually make it overall more readable
and what would you recommend??
Yeah, indeed, so you want to absorb and understand the idea behind the statement, and not take it as dogma, so you can apply it in a sensible way.
The most effective way to learn Python is incremental and practice-driven. Start with a structured introductory course that covers the basics (syntax, control flow, data structures), and actively do the exercises or small projects alongside it to apply what you learn immediately. Once you’ve completed that foundation, shift your focus to building your own projects, starting small and gradually increasing size and complexity. Real learning happens when you repeatedly encounter problems, try to solve them, and fill in the gaps in your understanding as they arise.
do you recommend any specfic course?
@ruby sable These ^
All of them are good
also are you prepared for questions like this every time beacuse you answered my question in like 3 seconds 😂
Yes
okay thank you
Made a custom keybind for it yet?
No, I have too many snippets
Maybe I should make some kinda tab-complete tool or something
def normalized_euclidean_distance(p1: tuple[float, ...], p2: tuple[float, ...]) -> float:
"""
Compute the Euclidean distance between two points and normalize it
by the dimensionality of the points.
Returns: Euclidean distance divided by the number of dimensions,
which allows distances to be compared across spaces of
different dimensionality.
"""
squared_diffs = [(a - b) ** 2 for a, b in zip(p1, p2)]
sum_of_squares = sum(squared_diffs)
# This expression would be unclear if returned inline
normalized_distance = (sum_of_squares ** 0.5) / len(p1)
return normalized_distance
```counterexample
and btw what is git and what is github for in general
ai bot
Wouldn't it be easier to just have a codeword you type that gets replaced with the entire yap text?
I mean the function is called "normalized_..._distance", so I dont think that last binding is really needed
i would say even if the comment tells you exactly why the function is used, you might still not understand it regardless
Git is a version control system for code. It basically lets you keep track of all previous versions of your code, so you can roll back changes to previous versions as needed. It also allows for having branching alternative histories. Github is a platform that lets you host Git repositories (basically codebases) on the cloud.
Well, it'd basically work like that, but dynamically.
based on the contents of the snippet
Advertising is not permitted here
i suppose you could infer it, but somehow i dont think return (sum_of_squares ** 0.5) / len(p1) is very clear on what it's doing when you read it
ohh
So Git is a software that you can run locally on your computer or on a server, and different instances of the software can communicate with other instances over the internet. Github is a web service that provides access to and hosting for Git.
that sounds useful
It's incredibly useful.
so useful that most software developers use it
Also nothing at that profile is related to python, and it's all clickbaity "most beginners confuse this" or "most people get it wrong"
i wish we had a better-than-git thing tbh
I like Git.
dropbox 🧠
@harsh swallow
dropbox does not compete with git at all
@harsh swallow it is beginning of something u can't even imagine....
you would think that, but you'd be mistaken. because people like using overleaf instead of writing latex locally, and overleaf syncs and backs up edit history automatically with dropbox, but requires manual commands with git
i dont like how overcomplicated it is
i mean why do we need two different ways to handle conflicts - rebase and merge?
why do i need to resolve conflicts before i can commit my code? what if i wanna do it tomorrow morning?
it's not the final form of version management i feel
(yes, latex writing is a big standard usecase for git)
an online latex ide that allows realtime collaboration
The difference between rebase and merge depends on how you want your commit graph to look like. Both are natural and valid options.
collaborating on a latex document sounds like a nightmare
that's why i prefer typst tbh
there's no difference in the usecase, except that typst has less support 😛
but it's less abnoxious to write
And I mean, if you wanna resolve conflicts tomorrow, wait with doing the merge until tomorrow?
imagine you'Re writing a 30 page typst document with 10 people and need to track changes
i still want my work to be saved
You can commit your changes on a different branch until then.
is there a way to avoid exec here?
[exec("z[x]=' '")for x,v in enumerate(z)if ...]```
I mean, committing and merging are different things.
You can do one and not the other.
z = [" " for _ in z if ...] ?
I'd strongly avoid shared branches in git, everyone should have their own branches which then merge separately from any specific commit
If you commit to a branch only you have, conflicts don't happen
You mean aside from the main branch?
there are some better tools out there nowadays, like google's jj
but because theyre not nearly as ubiquitous nobody actually uses them
Does it need to modify z or can you overwrite z entirely?
How does that handle synchronizing work in a way that's better than git?
IG it's more so that you shouldn't commit changes to a shared branch, but merge/rebase an existing branch instead.
Jj isn't a Google project unless something changed very recently
I'm pretty sure I can overwrite it
If you merge into the main branch, that creates a commit on it. That's unavoidable.
you can always do jj pull without ever having to worry about conflicts
all conflict resolutions are postponed to whenever you wanna deal with it
but basic operations never force you to stop everything and handle the conflict
z = [i for i, v in enumerate(z) if ... else v]
If you work in a feature branch in git, you don't have to worry about conflicts either.
Conflicts only happen when you merge the main branch into your feature branch.
wait that's not how that works
that is an interesting way to do that
it's so I can make it all one line
if you're interested i suggest trying these https://learngitbranching.js.org/
can stay in the website itself and get a good grasp of the concepts, plus you need to solve challenges
z = [i if ... else v for i, v in enumerate(z)]
cc @mossy sigil
wanna make email automatically generetor.
Wait you are not even using the i
z = [' ' if ... else x for x in z]
you still have the same problems if you work on shared branches though 
this is the full thing
import sys
z=[*sys.argv[1].replace(*" .")]
for i in range(250):
[exec("z[x]=' '")for x,v in enumerate(z)if v=="."and sum(1for y in[z[x+1],z[x-1],z[x+52],z[x-52]]if y in"# ")>2]
print(*z,sep="")```
so I do need the i
!rule ads are not allowed
eventually youll need to merge it into main or rebase it or whatever
if you just want to pull the latest update, i dont think it should ever throw you into a merge
it's a different system, im not sure im doing the best job explaining
my point is that there are pain points in git. i dont like it personally. i wish i didnt need to think about branches and merge conflicts and spiraling into these long and elaborate merge tasks when i just want to do something basic like pulling code
yeah no need for exec, just if/else with ' ' and v
these problems must exist, though. any version control system has to deal with conflicts
if you just want to do this, you can just git clone. otherwise, there's no sidestepping the issue. jj just has you do it differently
the difference is when you have to deal with them
in git you need to deal with them asap
I'm just saying that if you use feature branches, you don't get that specific issue you brought up where you are forced to resolve a conflict before you can save your work. You can always safely save your work in your feature branch, and only when you are ready to handle a conflict do you need to merge in the main branch.
They were already told that, yet they reposted
you could do ```py
z=[" "if v=="."and sum(1for y in[z[x+1],z[x-1],z[x+52],z[x-52]]if y in"# ")>2 else v for x,v in enumerate(z)]
oop actually
it's a little smaller. i forgot the whitespace in the indexing
If you want the latest updates in git, you should git fetch
Git pull is just git fetch, followed by a merge/fast-forward/rebase depending on config
i want to see the new pulled code in my repo
i just dont want to deal with merging it rn
does that make sense?
you can do that, just look at it on main, not on your feature branch.
You can IIRC detach to remote branches
hi
So you could just git switch -d origin/main to get the up to date code (as long as it wouldn't discard your local changes)
Jj is better here in that it just has your local changes automatically
that's another thing.. git has a ton of subcommands
like a ton
You can compact it here ```py
sum(1for y in[z[x+1],z[x-1],z[x+52],z[x-52]]if y in"# ")>2
sum(y in"# "for y in[z[x+1],z[x-1],z[x+52],z[x-52]])>2
ive been using git for years and i still dont understand half of the features
Git is very complex, that is true
I'd be surprised if most experienced git users could run git am first try correctly from memory
i think we can do much better than that
i understand why git is so popular, it was just better than what the ancient ones had before
but like... i dont need all that archaic complexity that's very fine-tuned for mailinglists
Well, Kernel devs definitely could
have you tried jj?
They were just talking about it
for a while i did, but nobody else uses it so i still use git day-to-day
there's no point being the only one using some version control tool 🤷
i thought you could use jj on a git repo and no one else you work with needs to use jj?
The key question with jj is whether it'll keep its superiority as it grows more features
thanks
how are you a jj user but don't know you can use it with existing git repos
you can do that, but i dont like the idea of using different tools than my peers
whenever i work with people i try to use the same tools as they are, it reduces friction
time to get comfortable with git I guess.
I'm all for new innovations, I just want to understand what the problems we're addressing are specifically.
im probably not the best person to explain it in all honesty
it just doesnt feel that good to use git, it's complex and has a ton of commands, and a lot of different ways to accomplish the same task
that makes it feel bad for me, if that makes sense
JJ removes the staging area, adjusts defaults in a way that is friendlier to common workflows, and has a more reliable undo. It also makes an effort to make it difficult to lose work
i was doing https://learngitbranching.js.org/ so that i can try jj and then appreciate it, ill probably do the second part when im free
git seems terrible until you have to use perforce
ugh, it was the worst
Hm, I can't relate to that personally, but I'm a pretty experienced user at this point. I'm ok with innovations that make tools more accessible to less experienced users as well, even if it doesn't do much for me.
i dont doubt that we can have it worse than git 😅
"was"? 😭😭
for me
Maybe it's because I came from CVS and SVN...
It's important to keep in mind that git did beat all version control Software that came before it, yeah
there was a push to switch to git a while back at work. it didn't go anywhere, unfortunately. though some projects are on git, most code is still in p4
You can still use SVN/CVS/...
And generally I think people do agree that git was indeed an improvement
git's flexibility can be an advantage as well. I'm still discovering new ways to use it in useful ways even today.
i think git did struggle with very large repos until quite recently with MS's improvements
ill freely admit im not some git guru, i have to use google quite a lot to remember what's the name of that one command that lets me selectively stage different parts of a file
it's just that i also dont think i should spend so much time to explore and master this tool, when the only thing i want from it is the ability to remember all my changes, and help me syncrhonize with other people
the fewer errors i see when i do some basic operation, the happier i am
make a list of the six different things you need to do. Research how to do them, make a cheat sheet (or git aliases). Then move on.
In my experience I only need a small subset of features and commands 99+% of the time
And it doesn't take that long to learn those
i mean it wont take much time to learn git, try that website i linked earlier
but there's nothing wrong with just using jj yeah
it always takes time to learn something
And if I ever need something more complex, I usually write shellscripts to make it easier to use
yes, but it will be worth it.
don't be like the person that comes here and just says "Python is too advanced for me! 🙁 "
prob more than you think, i would be so happy if you tried that website and then told me how you felt
that website really made things click for me
it is worth it, but only because it's the tool that everyone uses. it's not something i want to learn, it's something i have to learn
i would probably be happiest if git was just less annoying, but it is what it is
there's a lot of sites like it
like this one for example: https://rogerdudler.github.io/git-guide/
I think a lot of things feel more frustrating and annoying the less well you understand them.
no, i dont like the design and levels and whatnot
i dont want to gamify it
crazy
no offense but playing a git game is not how i want to spend my time learning something
also - i hate modals
these popup windows that darken the rest of the screen and just wont go away until i click that one specific button
ugh, please webdevs stop doing this
at least make it so clicking outside the modal closes it
modals are for UX right
educational games are a thing tho
it should go, when we click elsewhere
theyre usually worse than normal games and normal learning materials
worst of all worlds
That's how are normal modal works
it's not how it works in quite a few websites ive visited
it's how it should work
I'm reading through Beej's Guide to Git right now, and I think you might like it. All textual, no gamification.
yo i kinda need some projects to land a job.. anyone interested in collaborating?
have you made anything recently?
that's neat, i might go ahead and just read that actually
i like clean websites
i made a scraper recently but im still a bit rusty to be completely honest.
what do you plan on making for the next project?
was thinking on an API with fastAPI and then some AI functionality (which I have no experience on)
do you pythoneers actually share python files nowadays?
i remember there was a time when sending someone a single .py file that does whatever was common practice
it seems the standard way people share code now is packages
For what purpose?
if its a quick script , i dont think anyone makes it into a package to send it
its fine to just send the .py file imo
gemini flash has an api that allows like 2000 requests per hr or so
for free
both for scripts and as libraries
one file libraries went out of fashion 
Like if I wrote a script and someone else wants to use it?
depends on the size
I don't do python much profressionally, but when I do it's short one file scripts
GitHub repositories or gists
depending on the use case, package it and upload to pypi
ngl im immediately sus of anyone that just gives me a random .py fille
upload it to gists or something
If I just want to make a quick script I wrote available to other people, I'd put it on Github
put in pypy
Could be in a repo or in a gist
its easy?
wooo 25hour loonies
Made a Real Estate website scraper, was thinking on a CRM or data pipeline project now (pdf reports > database > data viz )
thanks
that was a common thing back in the day
before github was a thing
you could also send a zip with a directory, and treat it as a big script with __init__.py
it was all seemingly geared towards that idea of sharing code
If it's a multi-file project I'd make a repo. And I guess if the number of users started to scale up I'd consider putting it on pypi.
formatting it as a package is a little complex, but after that uploading to pypi is easy
https://packaging.python.org/en/latest/tutorials/packaging-projects/ explains it
But that never happened so far.
👍
i think distribution utilities only became a thing in like 2005 or something
I only know 1 project that shares a python file https://github.com/9001/copyparty and its pretty cool
how back in the day are we talking & through what would you send the file from?
like 90s to early 2000
Alrighty
so when internet wasnt a thing like it is today
i would assume almost everything was done differently in those days
because interenet wasnt as big and vast as it is now
so it would make sense that people only shared what was required
pip didnt exist either back then
So filezilla into some common sftp prolly
Some projects put stuff into a single Python file with the expectation that you just vendor it into your project. For example https://github.com/bottlepy/bottle
oh wait... CDs was a thing
"where is my python program"
"i already shipped it through speedpost"
that's neat
i always liked that concept because of how clean it looks
a file with thousands of lines isn't very clean imo
ah so its like copyparty. nice
now watch them come to the conclusion of "it depends"
?
single-file C codes are pretty epic 😎
none of that make nonsense
C and the C world are very far from my notion of 'clean'
there is a reason why tools like make exists
i recall using a single-file GUI library in C and it was great
you can still do unity builds though , thats a thing
yes but make is just dreadful
i dont wish my greatest enemies to waddle through the make soup
As much as vendoring seems cool, if it's a non-trivial project, you lose all the upsides of modern dependency management. Like getting an alert if the library you're using has a vulnerability you should patch
i mean with C/C++ , everything sucks
cmake seems to suck the least though , people like it
I've seen many people complain about CMake lol
I haven't had a chance to try meson yet though
Need an email provider ASAP need to migrate 50 domains, any ideas
In talks with PurelyMail and Mailgun but need a quicker process
have you seen this one? https://github.com/JimmyLefevre/kb
it's quite surprising how much work you can do in a single file even for non-trivial projects
Just transactional emails like myapp@example.com or does it also include user emails like john@example.com?
Purely transactional
I like Resend.com
Do they have a lengthy review process?
Not sure what the review process is for. Just hook your domain in, create an API key and you're set (sorta, still need to develop for Resend API)
No SMTP relay?
Why would you need a SMTP relay?
Its really straightforward https://resend.com/docs/send-with-python
Will keep this in mind thank you
Newbie quesion.... If there is a red circle with a "1" inside it in another channel, how do I find that message for me?
you can click the "Inbox" on the top-right of your Discord, then "Mentions"
you can go to the search bar and press mentions and fill out your name like mentions:_.steel._
there's also the bell icon on the channels/servers page in mobile
I;m on desktop
Thanks
Thanks
Turns out it was just more insults, so I guess I didn't miss much
This square with the red buble
But at least now I won't miss insults when I am away!! 😉
And how do I give a thumbs up to a message - or can you not do that on this server?
Thanks
disabled in this channel because of spam bots
A-ha
Thanks for the help everyone
Have you ever dealt with Amazon SES for transactional emails
Hi
Why in the world did I choose audio transcription/anything audio related as part of a first project lmao
holy hell this is a brainfuck
well there's ya problem
you should be writing python instead
is there a discord server for discussing AI/ML which is as active as this?
they might both be programming languages but brainfuck is significantly worse
||pydis||
thank you!
its a joke
I hate using chatgpt to help guide me through things but its quicker than asking questions in places that nobody answers lol
pydis is python discord
i got it now 😂
what's your question
don't really have a specific one atm, havent messed with this stuff in a bit.
what's the most reputed subfield in AI? as in hard and reputable to publish in?
What I'm trying to accomplish though is even a basic working AI assistant, which I had working for a moment but it was giving me phantom transcriptions
i worked on adding webrtcvad and it muffed everything up, ended up losing the code I had before out of frustration
sounds difficult
how to you even measure that?
maybe you should try something so the difficulty curve is not that steep
that would bore me to pieces making things that i have no use for/interest in, tbh
i'm not sure, i'm not even in the AI field. i could give an example: like algebraic geometry considered terse in math.
id lose interest in even trying at that point
Hello all :) I'm having a bit of an issue with incremental names, I have a list of names:
basename > basename_01
basename.001 > basename_02
basename.002 > basename_03
and so on...
this is the end result I'm trying to achieve, but i have no clue how to approach it
filenames?
why does basename.001 get turned into basename_02?
because basename gets that spot
its names in blender, with anything, if theres a duplicate of an object, it adds .00N and goes up but .001 is the second object not the first
exactly :)
...i was trying to guide them

oh sorry lol
Hmm
i see
what does basename.012 get mapped to
basename_13
why?
because its the numbers + 1
how did you get 12 from basename.012
which part of the filename did you look at to get the number
how did you tell that it is part of the number sequence and not the filename
the suffix!
how do you tell which part is the suffix
anything after the .
oh ok ok
"how to split string at character python"
What can i do with beatifulSoup
@pallid garden you can also use pathlib to get the parts of a filename (cross-platform)
so using .split(".")? :o
ohhhh
how do you turn a string of characters into a number
Hii
int(), typically
sorry, I misread the context
hiii
(my window was only showing me the last couple of msgs)
anyway, now that we got our 12
so i take the string and use int()!
@cold bronze how do you turn 13 into basename_13
The Socratic Method vs pydis' will to answer every question it can
And some kind of help is the kind of help ... we can all do without
Are expressions and operations same things?
binary operations are expressions in Python
binary operations as in operations that have two operands and one operator
actually, all operand based operations are expressions in Python
Traceback (most recent call last):
File "C:\Users\liebe\OneDrive\programming\ls_project\main.py", line 9, in <module>
for file in file_or_dir.iterdir():
~~~~~~~~~~~~~~~~~~~^^
File "C:\Users\liebe\AppData\Local\Programs\Python\Python314\Lib\pathlib_init_.py", line 836, in iterdir
with os.scandir(root_dir) as scandir_it:
~~~~~~~~~~^^^^^^^^^^
NotADirectoryError: [WinError 267] The directory name is invalid: 'C:\Users\liebe\OneDrive\programming\ls_project\main.py'
can someone help me understand whats wrong
what does the last line say
basename + "_" + int(13)?
good
smth to do with my directory
earlier we used split to get the basename as a component of the filename right, with the suffix number as the other component
so we can use basename
I am not able to understand first two points?
ahhhh!
well, whats the error
NotADirectoryError: [WinError 267] The directory name is invalid: 'C:\Users\liebe\OneDrive\programming\ls_project\main.py'
smth to do with this i think
notadirectoryerror
ok...
😭
and?
the name is invalid
there's still more
C:\Users\liebe\OneDrive\programming\ls_project\main.py idk why its getting rid of \ in my messages
sometimes errors are slightly misleading. the clues are all there though
that's not the problem.
oh
you said "the name is invalid". there was another word there.
In python are expressesions and operations the same thing?
The directory name is invalid:
"directory"
Traceback (most recent call last):
File "C:\Users\liebe\OneDrive\programming\ls_project\main.py", line 13, in <module>
for file in file_or_dir.iterdir():
~~~~~~~~~~~~~~~~~~~^^ smth wrong here
so binary means two, right?
in maths, and in python, a "binary operation" is an operation involving two operands (basically, variables) and one operator (like +, -, *, /)
so an example of a binary operation would be: 1 + 2 or 3 * 4
there are also unary operations like -1 where - is the operator and 1 is the operand
an "expression" is just something that evaluates to something, think of it as things that can be assigned to a variable
x = 5 + 2, the 5 + 2 is an expression
but x = return 5 wouldnt work because return 5 is not an expression
is C:\Users\liebe\OneDrive\programming\ls_project\main.py a directory?
no
oh i see the problem
you'd be surprised how good python's error messages are once you see other languages
Understood thanks.
"invalid" there seems misleading to me
but i still want to be able to cd on it shouldnt i? or should i leave it like this
Enter a folder name: ls_project
ls
.idea
.venv
main.py
programming
without trying to cd now into .idea .venv
there are some languages with errors which are completely indecipherable
...i think perhaps habitually i see this as normal, but someone else might not
What would it mean to cd into a file?
call direct-
to lazy to finish the sentence xd
opening a file is very different from changing to a directory, despite both of them being a double click in the GUI
wdym?
PS C:\Users\liebe\OneDrive\programming\ls_project> cd .venv
PS C:\Users\liebe\OneDrive\programming\ls_project.venv> cd
PS C:\Users\liebe\OneDrive\programming\ls_project.venv> cd
PS C:\Users\liebe\OneDrive\programming\ls_project.venv> ls
Directory: C:\Users\liebe\OneDrive\programming\ls_project\.venv
just tryna do smth like this
I think I figured it out!
name = "basename.001"
basename = name.split(".")[0]
suffix = name.split(".")[1]
newsuffix = int(suffix) + 1
newname = basename + "_" + str(newsuffix)
is brocode good for python?
eventually you will get the hang of how to break down your own thought process and it will become second nature to you
else:
for file_or_dir in current_folder.iterdir():
if file_or_dir.is_dir():
for file in file_or_dir.iterdir():
print(file.name)
else:
print("Not a directory")
figured it out
Thank you for your help and patience :) I'm still new to python but it makes sense now
no more errors only focuses on my directs
If it gets you writing your own code and making your own mistakes, yes!
keep it up!
never tried him and idk who should i watch
Will do!
but does it work for plain "basename"?
I was about to ask :P since the base name has no second component, i wanted to check if its None, but it returns an error
i think they know how to branch with if?
nvm
umm so this is a special case right?
when there is no suffix and no .
yeah!
there are a few ways to solve this
Enter a folder name: programming
ls_project
.idea
.venv
main.py
im almost done my cd/ls program yippe
@cold bronze question, can the basename ever have an extension of its own? like image.jpg.001 etc
It could have side suffix, meaning "basename.L" for left, and .R for right
and then you'd have basename.L.001, basename.R.001, and so on?
yes exactly
So i'd have to check with an if statement
the numbering is always the last segment right?
yes!
how do you get the last segment of a list?
yup
Whats #black-formatter
so i can check if the last element is an integer!
damn, you learn fast
haha thank you :) I'm glad
is brocode good for python?
try corey schafer instead
A formatter for Python code
why tho
no
how would you check?
why
So i can use isinstance to check its type right?
on line 17 i do current_folder = Path(current_folder) / split_ls_cd[1]
and on line 8 i have
current_folder = Path(origin_folder) / location
it will overwrite line 8 right the variable(thats what i want it to do)
or if type(x) == int
not in this case
No
ahh ok
type
when you split the filename, each segment is a string right?
just not good
they are not integers yet
What do you expect isinstance("001", int) to give you?
and what would u recommend
an error i assume 😅
or false
try it
cause its a string
we think brocode encourages people to copy code instead of understand what the code does
hmm fair
why would you say "we"
its an organization of a bunch of ppl
the evidence being people coming into this server having copied the code incorrectly and not being able to understand the error they are getting
is python THAT hard?
no, but finding a good teacher is
so I'd have to convert it into an int first, but when i try to do that with a string it returns an error
What do you mean by "that"?
my school teacher is ass
I think copying code is just a stage of learning. I certainly had a copying phase when I was starting out
real
i copied code, and then toyed with them to see what happens when i change something
loot of code? or just small snippets
when did u start learning
start of 2014
yeah, me too
damn
i don't think most people tinker with the code though
sometimes small sometimes large. it was whatever I could find ig
what do you think you've learned from this?
yes, so you know that if it succeeds, it's an int, and if it errors, it's not
tinkerers tend to have an easier time with code
Does anyone here know if it’s possible to look at like TikTok’s http request and see why they’re giving an error message for something specific in the app?
depends on what you count as “tinkering”. beginners can tinker by changing formatting, variable names, or string content, and that usually feels pretty rewarding
yeah my friend was changing box size pos color..
do they do that by themslves?
dk if he was learning anything tho
Maybe. But usually you can’t do anything about it
Ahats a formatter
I found that I really liked the feeling of building something and seeing it work. for me, copying code was more about finding the passion rather than learning it
interesting
It’s for an event they’re doing , they require you to invite a new user but it only works 50/50 of the time for me so I was trying to see why some phones get the error and some work, was hoping to know if it could spit out some useful account information


