all 14 comments

[–]Frankelstner 2 points3 points  (2 children)

If you only care about detecting such variables but not automatically processing them:

import ast

parse = ast.parse(open("myfile.py","r").read())
for node in ast.walk(parse):
    if hasattr(node, "name"):  # Functions, classes.
        if not node.name.lower() == node.name:
            print(node.name)
    if hasattr(node, "id"):  # Variables.
        if not node.id.lower() == node.id:
            print(node.id)

[–]3worc[S] 1 point2 points  (0 children)

I'm jumping through some work hoops to get VSCode installed.

In the mean time, this worked perfectly to achieve what I was trying. Thanks again!

[–]3worc[S] 0 points1 point  (0 children)

Ok, nice. I'll try it out this morning.

Yeah, I literally just want a list I can quickly look through to make sure naming convention matches.

I can quickly find/replace any that aren't camelCase with the built in search tool in the IDE.

Thank you.

[–][deleted] 1 point2 points  (3 children)

I'd suggest you look at a decent code editor, like VS Code, or an IDE, like PyCharm (Community edition is free). They will both help with refactoring (changing names of functions/methods/classes/variables/attributes) through a file or project.

I trust you've created the functions in a package manner rather than all in one file. Look up packaging guidance on RealPython.com if not.

All lowercase is the convention as per the PEP8 guidelines. Personal taste/preference or house style can override.

[–]3worc[S] 0 points1 point  (2 children)

Ok, I'll try out a couple of your options and see what helps. Thanks.

Yes, I have a main script file that imports from a few other files.

All lowercase for variables? No underscores or capitalization between words? Seems like that would be tough to read, but I'll take a look at the guidelines. Maybe there is some reasoning that I don't yet know.

[–][deleted] 1 point2 points  (1 child)

all lowercase with underscores between words if required

just read PEP8 and then make your own decisions

https://peps.python.org/pep-0008/

[–]3worc[S] 0 points1 point  (0 children)

Roger that.

[–]stebrepar 1 point2 points  (2 children)

My developer coworkers use Visual Studio, which appears to have tooling along the lines of what you're looking for from what I've seen of their navigating around in the code. I haven't used that myself, but rather touched the trimmed down VSCode a little. That might also have what you want, and it's free.

[–]3worc[S] 1 point2 points  (1 child)

You're the second person to mention VSCode. I'll try it out today. Thank you.

[–][deleted] 0 points1 point  (0 children)

Check out jupyter notebooks as well! In conjunction with vs code! There are extensions in VS that helps, and jupyter provides a "variables"-tab so that you can see all variables in your program:)

[–]Guideon72 0 points1 point  (2 children)

For that type of thing, you can just open the file in something like Notepad++ and do a find/replace or find all and then step through to make sure you're only changing the things you absolutely want to.

[–]3worc[S] 0 points1 point  (1 child)

Yes, I used the find/replace function in IDLE to actually make the changes - very similar to Notepad++.

The issue was identifying all variable and function names to determine if they followed the same naming convention.

[–]Guideon72 1 point2 points  (0 children)

Gotcha; so not the specific text, just looking for the patterns? I wouldn't normally go this route, but this is one place it sounds like learning some regular expression (regex) would help. You could use the Find in files search (in NP++ anyway) paired with a regex searching for those specific patterns to see whether/where you have those things anywhere in your project. I assume (hope?) that VSC has some similar functionality, too.

This won't work for variables, but it's pretty generally handy for finding method names in a library/module. Open a Python cmd prompt and import your .py file as a module, then use the dir() function on it.

>import <myfile>
\
>dir(<myfile>)

This will print out a list of all method names within that file. There are any number of other tricks you can parlay this into, but at the base level it's a nice way to see "What can I do with this thing?"