Comments (8)
The current code is correct, but the try / except can be removed as there will be no exception.
Putting in a second parameter for getenv(varname, default) does already everything you intend to do, and you may .title() the result safely if you desire.
Below is a lengthy explanation, not to put in code:
If you were to handle not having a user name by doing anything beyond having a default, you'd need a None return value by not providing a default (omit the second parameter on the inner call to getenv).
Depending on weather you call .title() immediately: (// being a line break)
try: // currentusername = getenv(…).title() // except: // (print message, set default)
Or not: If currentusername is not None: // currentusername = currentusername.title() //else: // (print message, set default, slap user)
Both are correct, but the exception needs a comment explaining why you'd expect to arrive there:
# If neither environment variable is set, .title() will throw an exception on the Null value
Also I see you're testing for not-supplied parameters by converting to string and lowercasing (e.g. line 118, if str(filename).lower() == 'none'
). I assume if filename is None
would be correct, but I don't test that now.
from slic3rconfigprettyprint.
Works in Windows.
No reason not to use it: 363a486
from slic3rconfigprettyprint.
If you have a default parameter on the inner os.getenv('USER','default_string'), then there will not be any exception. If you want that, you should remove that, so None will be returned and .None.title() will throw the exception.
from slic3rconfigprettyprint.
Please try the new commit and let me know if that works now.
Sure, None is not a string ... maybe str(os.getenv('USER','default_string')).title()
would have sufficed.
from slic3rconfigprettyprint.
If you have a default parameter, then there will always be a string being returned and you can .title it.
Thus, currentusername = os.getenv('username', os.getenv('USER','Your Name')).title()
will never throw an exception.
My reasoning was that if you want to handle not finding the user name by exception, then you MUST NOT use a default parameter, but currentusername = os.getenv('username', os.getenv('USER')).title()
, then catch the exception and do whatever you want there.
Also: currentusername.title()
is documented to not modify the string.
If you want to use "Your Name" as a default, you can just put in that default, you will not get an exception as you will not get a None return value. Then you can call .title() and be done.
I'd suggest leaving it empty or to print a line so you can write in your name.
from slic3rconfigprettyprint.
Also: currentusername.title() is documented to not modify the string.
Yeah, I thought about that too ...
And, nah, I don't like exceptions :-) ! If someone has no username/USER in his/her system, so be it!
from slic3rconfigprettyprint.
Dude! I appreciate your lesson in programming (I am no programmer, obviously) but it's just a username on a report! Nothing more, nothing less!
I expect, if someone really will use this script, that he/she will provide the actual name - not the username on the computer. I use just some bogus thing myself.... so, if the script doesn't 'see' a username, then use a default. This will let the user know "hey, I can put my real name on this thing! : -)
I'll look over it again not to use useless/needless code - thanks!
from slic3rconfigprettyprint.
You need help, therefore I do help as much as I can. HTH, nor more nor less. Also I learned a little bit of silly snake.-)
from slic3rconfigprettyprint.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slic3rconfigprettyprint.