and just work with parameter passing.
>>
>
> Lovely, thank you. I started a project that is for learning spanish
> on-line, of currently 300 lines or so, that is proceeding rapidly
> thanks to these lessons learned. Thank you Python Tutors, and thank
> you Python!
Hola Luis,
I'd like to help with
> [Jeff]
> > Also, even though this is intended to be a quick shell script, it's
> > not a bad idea to make everything except function defs into a little
> > main() function, and call it in a script-only section.
>
>
> [Luis]
>
> > The only thing I'm not clear about is how 'trashcan' can be a
>
> file. This allows me to pass a single object that contains loads of
conf
> data to the important init functions (which my, indeed, change the
data
> depending on various factors). Now, memory wise this may not be the
best
> thing to do.
As a matter of interest why do you think its a problem memo
[edited for sanity]
> An advantage here is that this guess() function is less tied to outside
> global resources, and is, in theory, more easily reused. If we wanted to
> rewrite the program so that we take three different passwords, the version
> without global variables is easy to write:
>
>
> example. The only thing I'm not clear about is how 'trashcan' can be
a
> local variable inside main() when it's required by both trash() and
> can()
It's not local. It is a global variable. It is defined outside
of any of the functions.
> The only thing that's missing is that this script can't
[Jacob]
> > BTW, trashcan IS a module level variable because it's defined at the
> > module level. Why it says it's local is beyond me.
[Danny]
> Ah, you must be running into the global/local gotcha.
[long rambling text cut]
Wait, wait. Forget everything I said. *grin* I should have read the
On Sun, 26 Dec 2004, Jacob S. wrote:
> > The only thing that's missing is that this script can't handle paths
> > like ~/dir/junkthis
>
> I believe you're looking for os.path.expanduser("~/dir/junkthis")
>
> BTW, trashcan IS a module level variable because it's defined at the module
> level. Why
> The only thing that's missing is that this script can't handle paths
> like ~/dir/junkthis
I believe you're looking for os.path.expanduser("~/dir/junkthis")
BTW, trashcan IS a module level variable because it's defined at the module
level. Why it says it's local is beyond me.
HTH,
Jacob Schmid
Hi,
Jeff Shanon, thanks for your help. I was wondering if there was a
function to automatically get the user on a *nix system, and had tried
the if __name__ == __main__ but didn't really get it until your
example. The only thing I'm not clear about is how 'trashcan' can be a
local variable inside
> junk = []
> for arg in sys.argv:
> junk.append(arg)
>
> junk = junk[1:]
Why not
for arg in sys.argv[1:]:
junk.append(arg)
Or even easier and faster:
junk = sys.argv[1:]
All I had time to look at, sorry.
Alan G.
___
Tutor maillist - [E
Luis N wrote:
This is the most meaningful thing this newbie has ever done. Comments
are appreciated:
Okay, here's a few thoughts...
junk = []
for arg in sys.argv:
junk.append(arg)
junk = junk[1:]
You can write these four lines much simpler as:
junk = sys.argv[1:]
if len(junk) is 0 and empty ==
This is the most meaningful thing this newbie has ever done. Comments
are appreciated:
#!/usr/local/bin/python
trashcan = "/home/anewby/.trashcan"
import os, sys, shutil
junk = []
for arg in sys.argv:
junk.append(arg)
junk = junk[1:]
empty = False
if "-e" in junk:
empty = True
ju
12 matches
Mail list logo