Re: [Tutor] [Tutor} Why doesn't it choose a new number each time?

2007-02-15 Thread Nathan Pinno

Hey all,
 
I edited my code, and it seems to choose a new number each time. Maybe I didn't 
run my test long enough the first time?
 
I should have spotted the problem of
 
choice(range(3))
 
a mile away. I edited that bit, and now I think it's running right. (25 rounds 
of Rock, Paper, Scissors should be good enough testing, right? LOL) The new 
code is
 
choice(range(1,4))and that was a suggestion. (Thanks!) But can anyone explain 
why I can shorten the code? I looked at it a long while yesterday, and came up 
with nothing. The only thing I decided was to try to get it to the GUI stage.
 
Thanks,
Nathan
> Date: Wed, 14 Feb 2007 17:17:57 +0100> From: "Rikard Bosnjakovic" <[EMAIL 
> PROTECTED]>> Subject: Re: [Tutor] Why doesn't it choose a new number each 
> time?> To: tutor@python.org> Message-ID:> <[EMAIL PROTECTED]>> Content-Type: 
> text/plain; charset=ISO-8859-1; format=flowed> > On 2/14/07, Alan Gauld 
> <[EMAIL PROTECTED]> wrote:> > > I don't think that's a problem. The fact that 
> the computers numbers> > don't correspond with the users numbers shouldn't 
> matter provided> > the 'if' tests align with the choice result, which they 
> do.> > Alan,> > You're right, ofcourse. I approached the problem entirely> 
> pragmatically and somehow disregarded the original problem.> > Nathan, you 
> need to provide us more details. For example, what really> happens (which you 
> consider being a problem), and what do you want to> happen instead?> > > --> 
> - Rikard.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Tutor} Why doesn't it choose a new number each time?

2007-02-15 Thread Alan Gauld
"Nathan Pinno" <[EMAIL PROTECTED]> wrote

> But can anyone explain why I can shorten the code?

There are a few things you could do but one very powerful
trick is to use a table driven approach. Thus:

rps = {0:'rock',1:'paper',2:'scissors'}  # use zero to match list 
index

results = [
# zeroth item AI chose rock
 ['You chose Rock : Tied Game',
  'You chose Paper: You win!',
  'You chose scissors, AI Wins!'],
# index one is AI chose paper
 ['You chose Rock, AI Wins!'
  ...etc],
# index 3 AI chose scissors
 ['You chose Rock, You win!', etc]
]

Now all your if/else logic becomes:

tool = choice(range3))
user = int(raw_input()
print 'AI chose ', rps[tool], results[tool][user]

And you can reduce that further by using multiple tables
of strings and the results table simply becomes a collection
of indexes into those tables. This is starting to get into a
database topic called normal forms which is probably a
tad advanced for this case!

HTH,

Alan G.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Tutor} Why doesn't it choose a new number each time?

2007-02-15 Thread Rikard Bosnjakovic
On 2/15/07, Nathan Pinno <[EMAIL PROTECTED]> wrote:

> and that was a suggestion. (Thanks!) But can anyone explain why I can
> shorten the code? I looked at it a long while yesterday, and came up with
> nothing. The only thing I decided was to try to get it to the GUI stage.

If you take a look at your if-cases, you see that a lot of strings in
there are the same. The code is therefore redundant, and this is what
can be trimmed down.

Consider this code:

if var1 = 1 and var2 = 0:
  print "Var1 is 1, var2 is 0"
if var1 = 0 and var2 = 0:
  print "Var1 is 0, var2 is 0"
if var1 = 1 and var2 = 1:
  print "Var1 is 1, var2 is 1"
if var1 = 0 and var2 = 1:
  print "Var1 is 0, var2 is 1"

This scope is redundant in a lot of ways and can be trimmed down to
one if and one print:

if (var1 in [0,1]) and (var2 in [0,1]):
  print "Var1 is %d, var2 is %d" % (var1, var2)

Your code is similiar to the above. It takes time to learn how to trim
down redundant code. Vast knowledge of a language itself is not
required, but a pretty solid knowledge about the basics is probably
required. If you are entirely new to programming, it might be
cumbersome though.

Give it a try, and don't hesitate to ask again.

-- 
- Rikard.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Tutor} Why doesn't it choose a new number each time?

2007-02-15 Thread Luke Paireepinart
Rikard Bosnjakovic wrote:
> On 2/15/07, Nathan Pinno <[EMAIL PROTECTED]> wrote:
>
>   
>> and that was a suggestion. (Thanks!) But can anyone explain why I can
>> shorten the code? I looked at it a long while yesterday, and came up with
>> nothing. The only thing I decided was to try to get it to the GUI stage.
>> 
>
> If you take a look at your if-cases, you see that a lot of strings in
> there are the same. The code is therefore redundant, and this is what
> can be trimmed down.
>
> Consider this code:
>
> if var1 = 1 and var2 = 0:
>   print "Var1 is 1, var2 is 0"
> if var1 = 0 and var2 = 0:
>   print "Var1 is 0, var2 is 0"
> if var1 = 1 and var2 = 1:
>   print "Var1 is 1, var2 is 1"
> if var1 = 0 and var2 = 1:
>   print "Var1 is 0, var2 is 1"
>   
I think Rikard meant '==' in the above cases.
Not meaning to nitpick, just don't want someone copying and pasting this 
and ending up with weird results.
> This scope is redundant in a lot of ways and can be trimmed down to
> one if and one print:
>
> if (var1 in [0,1]) and (var2 in [0,1]):
>   print "Var1 is %d, var2 is %d" % (var1, var2)
>
> Your code is similiar to the above. It takes time to learn how to trim
> down redundant code. Vast knowledge of a language itself is not
> required, but a pretty solid knowledge about the basics is probably
> required. If you are entirely new to programming, it might be
> cumbersome though.
>
> Give it a try, and don't hesitate to ask again.
>
>   

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Tutor} Why doesn't it choose a new number each time?

2007-02-15 Thread Geoframer

The one thing people told me when i started learning python was that python
has this lovely structure called dictionaries. Your particular problem is
very easy to solve using dictionaries in about 12 lines (i coded it myself
just to see ;-)).

For instance you could define the various values as a dictionary :
values = {1:'rock', 2:'paper', 3:'scissors'}

and the outcome of possible combinations (cchoice, hchoice) as :
combinations = {(1,1):'Tie game!', (1,2):'You win!', (1,3):'You lost!',
(2,1):'You lost!', (2,2):'Tie game!', (2,3):'You win!',
  (3,1):'You win!', (3,2):'You lost!', (3,3):'Tie
game!'}

That way it's very easy to take a random value for computer , get input for
human player and print the result in a single print like so :
print "AI chose %s, you chose %s. %s", %(values.get(cchoice),values.get
(hchoice),combinations.get((cchoice,hchoice)))

Probably this is not unlike Alan suggest, but i got confused when i read
about tables. Unless he means dictionaries instead.

HTH - Geoframer

On 2/15/07, Rikard Bosnjakovic <[EMAIL PROTECTED]> wrote:


On 2/15/07, Nathan Pinno <[EMAIL PROTECTED]> wrote:

> and that was a suggestion. (Thanks!) But can anyone explain why I can
> shorten the code? I looked at it a long while yesterday, and came up
with
> nothing. The only thing I decided was to try to get it to the GUI stage.

If you take a look at your if-cases, you see that a lot of strings in
there are the same. The code is therefore redundant, and this is what
can be trimmed down.

Consider this code:

if var1 = 1 and var2 = 0:
  print "Var1 is 1, var2 is 0"
if var1 = 0 and var2 = 0:
  print "Var1 is 0, var2 is 0"
if var1 = 1 and var2 = 1:
  print "Var1 is 1, var2 is 1"
if var1 = 0 and var2 = 1:
  print "Var1 is 0, var2 is 1"

This scope is redundant in a lot of ways and can be trimmed down to
one if and one print:

if (var1 in [0,1]) and (var2 in [0,1]):
  print "Var1 is %d, var2 is %d" % (var1, var2)

Your code is similiar to the above. It takes time to learn how to trim
down redundant code. Vast knowledge of a language itself is not
required, but a pretty solid knowledge about the basics is probably
required. If you are entirely new to programming, it might be
cumbersome though.

Give it a try, and don't hesitate to ask again.

--
- Rikard.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Replying to the tutor-list

2007-02-15 Thread Andre Engels

2007/2/14, Alan Gauld <[EMAIL PROTECTED]>:


Because hitting Reply and sending to a list would only be
consistent if the list was the originator of the message.
Some mailing lists do implement this bizarre and
non-standard email behaviour but thankfully the Python
community doesn't! This behaviour has been standard
in email tools for over 25 years, let's not try to change
it now!



It's getting to be the majority of mailing lists that do it the other way,
and I find it quite irritating that this list does not - I have had several
times that I sent a mail, and after sending it, sometimes long after sending
it, I realize I sent it to the sender instead of the list, so I send a
second message after it. Who knows how often I have failed to do that?

--
Andre Engels, [EMAIL PROTECTED]
ICQ: 6260644  --  Skype: a_engels
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] arguments

2007-02-15 Thread emilia12


Hi list,

I have a function with two arguments (say f(x,y))
and second which returns tuple (say def g(): return (xx,yy))

my question is how to put returned values from g() as
arguments to f ?

the direct way generates error:

f(g())
TypeError: ff() takes exactly 2 arguments (1 given)

and the hard way is
x, y = g()
f(x,y)

is ok but it uses two extra variables. Is there a simple way
to do this?

BTW f(g()[0], g()[1]) works too, but calls function g()
twice ...

thanks in advance
e.



-

SCENA - Единственото БЕЗПЛАТНО списание за мобилни комуникации и технологии.
http://www.bgscena.com/

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] arguments

2007-02-15 Thread Kent Johnson
[EMAIL PROTECTED] wrote:
> 
> Hi list,
> 
> I have a function with two arguments (say f(x,y))
> and second which returns tuple (say def g(): return (xx,yy))
> 
> my question is how to put returned values from g() as
> arguments to f ?
> 
> the direct way generates error:
> 
> f(g())
> TypeError: ff() takes exactly 2 arguments (1 given)

Use f(*g())

The * syntax does exactly what you want - it takes a single sequence and 
interprets it as the full argument list.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] arguments

2007-02-15 Thread Gregor Lingl
[EMAIL PROTECTED] schrieb:

>Hi list,
>
>I have a function with two arguments (say f(x,y))
>and second which returns tuple (say def g(): return (xx,yy))
>
>my question is how to put returned values from g() as
>arguments to f ?
>  
>
There is a special *-operator, which inserts the components of an Argument
(which must be a sequence) into the parametersof the calling function:
 >>> def f(x,y):
print x,y

   
 >>> def g():
return -5,1001

 >>> f(*g())
-5 1001
 >>>
Regards,
Gregor



>the direct way generates error:
>
>f(g())
>TypeError: ff() takes exactly 2 arguments (1 given)
>
>and the hard way is
>x, y = g()
>f(x,y)
>
>is ok but it uses two extra variables. Is there a simple way
>to do this?
>
>BTW f(g()[0], g()[1]) works too, but calls function g()
>twice ...
>
>thanks in advance
>e.
>
>
>
>-
>
>SCENA - Единственото БЕЗПЛАТНО списание за мобилни комуникации и технологии.
>http://www.bgscena.com/
>
>___
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>  
>

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Replying to the tutor-list

2007-02-15 Thread Rikard Bosnjakovic
On 2/15/07, Andre Engels <[EMAIL PROTECTED]> wrote:

> It's getting to be the majority of mailing lists that do it the other way,
> and I find it quite irritating that this list does not - I have had several
> times that I sent a mail, and after sending it, sometimes long after sending
> it, I realize I sent it to the sender instead of the list, so I send a
> second message after it. Who knows how often I have failed to do that?

I second that.

This list is the only one I've seen that does not utilize a
reply-to-tag in the postings. Lots of my replies has gone to the
poster in question and not to the list (which was the intention).


-- 
- Rikard.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Replying to the tutor-list

2007-02-15 Thread Rikard Bosnjakovic
On 2/14/07, Mike Hansen <[EMAIL PROTECTED]> wrote:

> The following tutor faq has an explanation:
>
> http://www.python.org/infogami-faq/tutor/tutor-why-do-my-replies-go-to-t
> he-person-who-sent-the-message-and-not-to-the-list/

I think the argument in that "explanation" sucks.

A asks something, B replies A. C replies to B's post, correcting him
on a few things and at the same time asks A some new questions.

There is no point in letting B having the sole post sent to his mailbox.

And these "flamewars" that the FAQ describes occur too seldom for it
to be an argument of the sake of not having a reply-to-tag.

Just my two cents.


-- 
- Rikard.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Replying to the tutor-list

2007-02-15 Thread Richard Querin

On 2/14/07, Mike Hansen <[EMAIL PROTECTED]> wrote:



> The following tutor faq has an explanation:
>
> http://www.python.org/infogami-faq/tutor/tutor-why-do-my-replies-go-to-t
> he-person-who-sent-the-message-and-not-to-the-list/




It seems like this is designed for the 5% case when it makes the other 95%
of normal reply cases more difficult. I would (like to) think that the vast
majority of replies are meant for all eyes. I would think it's the
responsibility of the person replying if he/she wants to respond privately
only rather than making that the defacto default.

Hitting reply in Gmail responds only back to the sender and not to the list.
I've been corrected (politely I might add) on more than one occasion.

Either way, it's a good list though. ;)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Replying to the tutor-list

2007-02-15 Thread Alan Gauld
"Richard Querin" <[EMAIL PROTECTED]> wrote
>>
>> > The following tutor faq has an explanation:
>> >
>> > http://www.python.org/infogami-faq/tutor/tutor-why-do-my-replies-go-to-t
>> > he-person-who-sent-the-message-and-not-to-the-list/
>
> It seems like this is designed for the 5% case when it makes the 
> other 95%
> of normal reply cases more difficult.

I dunno about you but 95% of my email is private, only
about 5% comes from mailing lists.

> I would (like to) think that the vast majority of replies are
> meant for all eyes.

Thats why its called Rely *ALL*. Private is Reply, Public is Reply 
ALL.
Thats what email tools have done from day one.

> responsibility of the person replying if he/she wants to respond 
> privately
> only rather than making that the defacto default.

The default is hit ReplyAll.
Only use Reply when you specifically want to send privately...
If there is only one sender ReplyAll will only send to them (unless
you have asked it to send to you too, but thats nearly always
configurable and only useful if you don't automatically create a
Sent entry)

> Hitting reply in Gmail responds only back to the sender and not to 
> the list.

That's true of the vast majority of mail tools.
Its what the email usability standard says is supposed to be the
meaning of those buttons. Thatsd why they are named that way.

> I've been corrected (politely I might add) on more than one 
> occasion.

So just use ReplyAll all the time... unless you only want to send to
the sender. (What I have noticed is that some web based mail tools
don't seem to have ReplyAll as the default which is downright 
unfriendly
design...)

I'm really confused about why mailing lists seem to be moving in
this direction. It adds nothing and makes a very inconsistent user
experience IMHO.

(But then, I'm equally confused as to why anyone would prefer a web
forum over a news group, and that seems to happen too. Newsgroups
are far more powerful and web forums add zero so far as I can tell...)

Alan G
An internet old-timer :-)



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Tutor} Why doesn't it choose a new number each time?

2007-02-15 Thread Alan Gauld
"Geoframer" <[EMAIL PROTECTED]> wrote

> Probably this is not unlike Alan suggest, but i got confused when i 
> read
> about tables. Unless he means dictionaries instead.

I meant tables in a generic sense. I actually started using
a dictionary then changed to a list because its more generic..
But it could have been tuples, dictionaries, even database tables.
Any 2D storage mechanism.

The principles are exactly the same.

Alan G. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Replying to the tutor-list

2007-02-15 Thread Richard Querin

On 2/15/07, Alan Gauld <[EMAIL PROTECTED]> wrote:




I dunno about you but 95% of my email is private, only
about 5% comes from mailing lists.



Yeah, me too, but I guess it seems easier to just hit 'reply' 100% of the
time and have it go to the right recipient. My point really was that 95% of
the time, the recipient is everyone in the mailing list, and only 5% of the
time do I want to privately respond to a mailing list item.

I've just noticed that Gmail doesn't even show a reply-all button if there
is only one sender. If there is a cc included then it becomes available.
Either way I will just remember to hit reply-all. No big whup.

RQ
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Replying to the tutor-list

2007-02-15 Thread Andre Engels

2007/2/15, ALAN GAULD <[EMAIL PROTECTED]>:


 > realize I sent it to the sender instead of the list,
> so I send a second message after it.

So do you find it odd when dealing with normal email
and you hit reply and it only goes to the sender?



No, because it is sent by the sender to me, not to some list.

Or do you not use email beyond one to one and list

membership? Surely you are introducing inconsistent
behaviour between your private mail and your list mail??



No, in my private mail I hit 'reply' and I reply. In my mailing lists I hit
'reply' and reply.

I seriously cannot fathom why anyone would want a tool

that makes things operate two differenmt ways, one for
normal email and one for mailing lists. They all come into
the same mailbox, I want them all to work the same way!



Well, what is the 'same way'? When I reply, I reply. When I get something
from a person, and reply it goes to that person. When I read something on a
newsgroup and reply, it goes to that newsgroup. When I read something on a
forum and reply, it goes to that forum.

As a matter of interest, what happens if you hit ReplyAll

on the other style lists? I assume that would work as I
would expect and send to the list and sender?
If so how do you send to the sender only?



Change the address by hand. That's hard to do, it's true, but the number of
times I want to reply in person to a message on a list is so low that that's
no problem at all.


--
Andre Engels, [EMAIL PROTECTED]
ICQ: 6260644  --  Skype: a_engels
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Convert my .bat and .vbs to .py

2007-02-15 Thread Mark Bystry
Hello,

This is my first post. I have just begun to code with python. My goal is to 
convert about a dozen or 
so DOS/Windows batch scripts(.bat) and vbscripts(.vbs) that I use on a 
day-to-day basis to python so 
that they can be run on either my windows or linux workstations.

The first things that I want to learn is how to do basic stuff like copying, 
moving, and deleting 
files around from folder to folder. I have been in the help section of python 
(copyfile section) 
but I do not understand what I am doing wrong.


Here is my simple DOS batch file...

##
copy D:\PDF_Holding\*PRODUCTION.pdf Z:\
copy D:\PDF_Holding\*ILLUSTRATION.pdf H:\MARKETING\ILLUSTRATIONS\PRODUCT
pause

del *.pdf
##

Basically, it copies the "production" and "illustration" pdf files to certain 
folders than deletes 
the left over pdf files when done. Yes, I could move them instead of copying 
them.

I'm no asking for anyone to write this for me but if someone could lead me i 
the right direction, I 
would be grateful.

Thank-you.

Mark
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Convert my .bat and .vbs to .py

2007-02-15 Thread Tim Golden
Mark Bystry wrote:

> The first things that I want to learn is how to do basic stuff like copying, 
> moving, and deleting 
> files around from folder to folder. I have been in the help section of python 
> (copyfile section) 
> but I do not understand what I am doing wrong.

Welcome to Python. You probably want to look at the shutil
module, possibly combined with the os module:

http://docs.python.org/lib/module-shutil.html
http://docs.python.org/lib/os-file-dir.html

TJG
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Convert my .bat and .vbs to .py

2007-02-15 Thread Eric Walstad
Hey Mark, welcome aboard!

There are a few different approaches you could take to convert your
scripts.  If most of your scripts are related to copying/moving files,
I'd have a look at Python's shutil module.  I think it'll work in both
Windows and Linux but I don't have a Windows machine handy to test it.



Have fun,

Eric.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Convert my .bat and .vbs to .py

2007-02-15 Thread Rob Andrews
If you import os, os.path, and shutil (only the ones you need,
although I wind up using all three for this sort of task), you can do
all that you have in mind and more.

os.path opens up some pretty painless methods for doing things like
testing to make sure the file exists in a given location before
copying it (or deleting it), which can save a good bit of heartache.

shutil can be used for not only copying files, but even copying entire
directory trees.

-Rob A.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Convert my .bat and .vbs to .py

2007-02-15 Thread Alan Gauld

"Mark Bystry" <[EMAIL PROTECTED]> wrote

> My goal is to convert about a dozen or so DOS/Windows batch 
> scripts(.bat) and vbscripts(.vbs) that I use on a day-to-day basis 
> to python 

You might want to look at my Using the OS topic in my tutorial
It covers basic file manipulation and starting external programs 
etc.

> that they can be run on either my windows or linux workstations.

That might be harder than you think due to differences in paths etc.
Also some external commands will be different, and ones with the 
same name take different arguments/orders or args etc

If you write them in pure Python you should be OK but if you 
just run sequences of OS commands (typical of batch files) 
then you might run into problems.

> The first things that I want to learn is how to do basic stuff 
> like copying, moving, and deleting files around from folder to 
> folder. 

Try my tutor topic.


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Convert my .bat and .vbs to .py

2007-02-15 Thread Mike Hansen
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Mark Bystry
> Sent: Thursday, February 15, 2007 10:04 AM
> To: tutor@python.org
> Subject: [Tutor] Convert my .bat and .vbs to .py
> 
> Hello,
> 
> This is my first post. I have just begun to code with python. 
> My goal is to convert about a dozen or 
> so DOS/Windows batch scripts(.bat) and vbscripts(.vbs) that I 
> use on a day-to-day basis to python so 
> that they can be run on either my windows or linux workstations.
> 
> The first things that I want to learn is how to do basic 
> stuff like copying, moving, and deleting 
> files around from folder to folder. I have been in the help 
> section of python (copyfile section) 
> but I do not understand what I am doing wrong.
> 
> 
> Here is my simple DOS batch file...
> 
> ##
> copy D:\PDF_Holding\*PRODUCTION.pdf Z:\
> copy D:\PDF_Holding\*ILLUSTRATION.pdf 
> H:\MARKETING\ILLUSTRATIONS\PRODUCT
> pause
> 
> del *.pdf
> ##
> 
> Basically, it copies the "production" and "illustration" pdf 
> files to certain folders than deletes 
> the left over pdf files when done. Yes, I could move them 
> instead of copying them.
> 
> I'm no asking for anyone to write this for me but if someone 
> could lead me i the right direction, I 
> would be grateful.
> 
> Thank-you.
> 
> Mark

Maybe there's a way to use shutil's copytree function with os module's
remove function or shutil's rmtree function? If not, use the glob module
to gather the file names and then walk the results of the glob with a
for loop and use shutil's copyfile function.

Mike
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Convert my .bat and .vbs to .py

2007-02-15 Thread Rob Andrews
I can confirm it works nicely in Windows. I have a script I use
several times daily to create working directories on a local
workstation by copying over arbitrarily deep directory trees into an
"original files" directory under a root directory named by job number.
The local workstation on which I have python running is a Windows
machine, and it's agnostic about the operating systems of the network
drives from which the data is gathered.

Quite handy and not even a very long program after the try/except
bulletproofing is added.

-Rob A.

On 2/15/07, Eric Walstad <[EMAIL PROTECTED]> wrote:
> Hey Mark, welcome aboard!
>
> There are a few different approaches you could take to convert your
> scripts.  If most of your scripts are related to copying/moving files,
> I'd have a look at Python's shutil module.  I think it'll work in both
> Windows and Linux but I don't have a Windows machine handy to test it.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Convert my .bat and .vbs to .py

2007-02-15 Thread Mark Bystry
Wow! Got a lot of responses to my post. Thanks everyone. After reading all of 
them, I may have to 
learn by example after all.  I'm going to try Alan Gauld's tutorials first.

Mark

Alan Gauld wrote the following on 2/15/2007 12:39 PM:
> "Mark Bystry" <[EMAIL PROTECTED]> wrote
> 
>> My goal is to convert about a dozen or so DOS/Windows batch 
>> scripts(.bat) and vbscripts(.vbs) that I use on a day-to-day basis 
>> to python 
> 
> You might want to look at my Using the OS topic in my tutorial
> It covers basic file manipulation and starting external programs 
> etc.
> 
>> that they can be run on either my windows or linux workstations.
> 
> That might be harder than you think due to differences in paths etc.
> Also some external commands will be different, and ones with the 
> same name take different arguments/orders or args etc
> 
> If you write them in pure Python you should be OK but if you 
> just run sequences of OS commands (typical of batch files) 
> then you might run into problems.
> 
>> The first things that I want to learn is how to do basic stuff 
>> like copying, moving, and deleting files around from folder to 
>> folder. 
> 
> Try my tutor topic.
> 
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Convert my .bat and .vbs to .py

2007-02-15 Thread Mark Bystry
You guys are great! I'm not sure how I found this mailing list but I'm glad 
that I subscribed.

Mark

Rob Andrews wrote the following on 2/15/2007 1:23 PM:
> We're good like that. heh
> 
> On 2/15/07, Mark Bystry <[EMAIL PROTECTED]> wrote:
>> Wow! Got a lot of responses to my post. Thanks everyone. After reading all 
>> of them, I may have to
>> learn by example after all.  I'm going to try Alan Gauld's tutorials first.
>>
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Replying to the tutor-list

2007-02-15 Thread Bill Campbell
The major reason for not setting Reply-To: thelist is that it makes it
*SLIGHTLY* more difficult to post something to the list and replys should
go to the sender.  IHMO, one should have to go to a little bit of effort
before posting a message that may go to thousands of recipients.

Using the ``mutt'' mailer, this effort is simply pressing ``L'' instead of
``r'' when posting to the list and adding the listname to the subscribe
section of ~/.muttrc, hardly a major inconvenience.

http://www.unicom.com/pw/reply-to-harmful.html

...
Bill
--
INTERNET:   [EMAIL PROTECTED]  Bill Campbell; Celestial Software, LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
FAX:(206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676

``We believe...that a mugger will kill you in the half-second it takes to
draw from the holster, but won't harm you while you dial the police on your
cell phone, talk to the dispatcher and wait half an hour for officers to
arrive.'' -- Gun-Control Net-work Credo
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Convert my .bat and .vbs to .py

2007-02-15 Thread Mark Bystry
Well, immediately I am having problems. Be patient with me.

This what I have...

copy_file.py


import os
import shutil as sh

sh.copy('C:\testing_it.txt', 'D:\')
raw_input("Done!")



...and it's not working. Obviously, I'm trying to copy a text file on C:\ to 
D:\.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Convert my .bat and .vbs to .py

2007-02-15 Thread Rob Andrews
Ahh, yes. Your main trouble seems to be the use of \ instead of / in
'C:\testing_it.txt'

Windows uses \, whereas python uses /. So you can replace 'c:\'
with your choice of the following:

'c:/' (replacing \ with /)
r'c:\' (the 'r' before the string tells python it's a raw string)
'c:\\' (the first \ telling python to take the second \ at face value)

-Rob A.

On 2/15/07, Mark Bystry <[EMAIL PROTECTED]> wrote:
> Well, immediately I am having problems. Be patient with me.
>
> This what I have...
>
> copy_file.py
> 
>
> import os
> import shutil as sh
>
> sh.copy('C:\testing_it.txt', 'D:\')
> raw_input("Done!")
>
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Convert my .bat and .vbs to .py

2007-02-15 Thread Kent Johnson
Mark Bystry wrote:
> Well, immediately I am having problems. Be patient with me.

We will be, you're doing great so far :-)
> 
> This what I have...
> 
> copy_file.py
> 
> 
> import os
> import shutil as sh
> 
> sh.copy('C:\testing_it.txt', 'D:\')

Backslash is an escape character in Python string constants. \t actually 
inserts a tab character in the string.

You have several choices:

'C:/testing_it.txt' - forward slashes work fine too
'C:\\testing_it.txt' - double the \ to make it a literal.
r'C:\testing_it.txt' - 'r' prefix makes it a 'raw' string, backslashes 
are (mostly) treated as literals rather than escapes.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Convert my .bat and .vbs to .py

2007-02-15 Thread Mark Bystry
Jeez! I'm retarded. It works like a charm now.

Thanks for that Rob

Mark

Rob Andrews wrote the following on 2/15/2007 2:29 PM:
> Ahh, yes. Your main trouble seems to be the use of \ instead of / in
> 'C:\testing_it.txt'
> 
> Windows uses \, whereas python uses /. So you can replace 'c:\'
> with your choice of the following:
> 
> 'c:/' (replacing \ with /)
> r'c:\' (the 'r' before the string tells python it's a raw string)
> 'c:\\' (the first \ telling python to take the second \ at face value)
> 
> -Rob A.
> 
> On 2/15/07, Mark Bystry <[EMAIL PROTECTED]> wrote:
>> Well, immediately I am having problems. Be patient with me.
>>
>> This what I have...
>>
>> copy_file.py
>> 
>>
>> import os
>> import shutil as sh
>>
>> sh.copy('C:\testing_it.txt', 'D:\')
>> raw_input("Done!")
>>
>> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Convert my .bat and .vbs to .py

2007-02-15 Thread Eric Walstad
Hey Mark,
Mark Bystry wrote:
> sh.copy('C:\testing_it.txt', 'D:\')

Also have a look at the os.path module.  Because you want these scripts
to work on both Linux and Windows, using os.path will let you avoid
writing platform specific code to handle your slashes.

For example:
import os
path_parts_list = ['C:', 'testing_it.txt']

Now, os.path.join will join those path parts together with whatever is
appropriate for the OS you are running on:

os.path.join(path_parts_list)

This should give you:
'c:\testing_it.txt' on Windows and
'c:/testing_it.txt' on Linux (which doesn't make sense, but demonstrates
how os.path can handle your os-specific slashes for you).

There are lots of helpful path related built-ins:

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Convert my .bat and .vbs to .py

2007-02-15 Thread Mark Bystry
Ahh. Great tip Eric. Thank-you.

Mark


Eric Walstad wrote the following on 2/15/2007 2:58 PM:
> Hey Mark,
> Mark Bystry wrote:
>> sh.copy('C:\testing_it.txt', 'D:\')
> 
> Also have a look at the os.path module.  Because you want these scripts
> to work on both Linux and Windows, using os.path will let you avoid
> writing platform specific code to handle your slashes.
> 
> For example:
> import os
> path_parts_list = ['C:', 'testing_it.txt']
> 
> Now, os.path.join will join those path parts together with whatever is
> appropriate for the OS you are running on:
> 
> os.path.join(path_parts_list)
> 
> This should give you:
> 'c:\testing_it.txt' on Windows and
> 'c:/testing_it.txt' on Linux (which doesn't make sense, but demonstrates
> how os.path can handle your os-specific slashes for you).
> 
> There are lots of helpful path related built-ins:
> 
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How do I compile Python for people so they don't have to download?

2007-02-15 Thread C. Gander
I downloaded py2exe and I thought it was a program that you just browsed 
your driver and gave it the .py file and it would do the rest. But I 
downloaded it and I cannot figure out how to use it. Please help.

_
Get in the mood for Valentine's Day. View photos, recipes and more on your 
Live.com page. 
http://www.live.com/?addTemplate=ValentinesDay&ocid=T001MSN30A0701

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do I compile Python for people so they don't have to download?

2007-02-15 Thread Rikard Bosnjakovic
On 2/16/07, C. Gander <[EMAIL PROTECTED]> wrote:

> I downloaded py2exe and I thought it was a program that you just browsed
> your driver and gave it the .py file and it would do the rest. But I
> downloaded it and I cannot figure out how to use it. Please help.

You don't have to "figure it out", you simply peek the tutorial. Have
it a go here:

http://www.py2exe.org/index.cgi/Tutorial

or the FAQ, here:

http://www.py2exe.org/index.cgi/FAQ


-- 
- Rikard.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Replying to the tutor-list

2007-02-15 Thread Luke Paireepinart
Bill Campbell wrote:
> The major reason for not setting Reply-To: thelist is that it makes it
> *SLIGHTLY* more difficult to post something to the list and replys should
> go to the sender.  IHMO, one should have to go to a little bit of effort
> before posting a message that may go to thousands of recipients.
>
> Using the ``mutt'' mailer, this effort is simply pressing ``L'' instead of
> ``r'' when posting to the list and adding the listname to the subscribe
> section of ~/.muttrc, hardly a major inconvenience.
>   
It's not the inconvenience but the fact that it's nonstandard, as far as 
every mailing list i've been on except this.
You don't pick people to mail specifically on the mailing list, why 
should you reply to specific people, unless you hit a special button?
I didn't get the e-mail from you.  You posted the e-mail to the list and 
i received it because I'm a member of the list.
The list is the sender.  It aggregates posts to me.  When I reply it 
should put my post in the same thread, one level below and immediately after
the previous person's post, like i expect it to.
It has retrained me to use reply-all, but I still don't like it.
Also you end up CCing copies of your e-mails to everyone.
>   http://www.unicom.com/pw/reply-to-harmful.html
>
> ...
> Bill
> --
> INTERNET:   [EMAIL PROTECTED]  Bill Campbell; Celestial Software, LLC
> URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
> FAX:(206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676
>
> ``We believe...that a mugger will kill you in the half-second it takes to
> draw from the holster, but won't harm you while you dial the police on your
> cell phone, talk to the dispatcher and wait half an hour for officers to
> arrive.'' -- Gun-Control Net-work Credo
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>   

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Replying to the tutor-list

2007-02-15 Thread Bill Campbell
On Thu, Feb 15, 2007, Luke Paireepinart wrote:
>Bill Campbell wrote:
>> The major reason for not setting Reply-To: thelist is that it makes it
>> *SLIGHTLY* more difficult to post something to the list and replys should
>> go to the sender.  IHMO, one should have to go to a little bit of effort
>> before posting a message that may go to thousands of recipients.
>>
>> Using the ``mutt'' mailer, this effort is simply pressing ``L'' instead of
>> ``r'' when posting to the list and adding the listname to the subscribe
>> section of ~/.muttrc, hardly a major inconvenience.
>>   
>It's not the inconvenience but the fact that it's nonstandard, as far as 
>every mailing list i've been on except this.

Hardly non-standrd.  The option for this in the Mailman MLM is:

 Where are replies to list messages directed? Poster is strongly
 recommended for most mailing lists.

I've been maintaining various technical mailing lists for over twenty years
now, and see this same thread come up many times.

Having the Reply-To: to the original poster minimizes the probability of
somebody sending mail to a list that was intended for the original poster
(which may be private).  The only advantage of having it set to the list is
it makes it easier for lazy people to send nonsense to hundreds of people.

As I said in my original message, it should require a little bit of effort
to send messages to hundreds or thousands of recipients.

Bill
--
INTERNET:   [EMAIL PROTECTED]  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
FAX:(206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676

It is necessary for the welfare of society that genius should be
privileged to utter sedition, to blaspheme, to outrage good taste, to
corrupt the youthful mind, and generally to scandalize one's uncles.
-- George Bernard Shaw
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Replying to the tutor-list

2007-02-15 Thread Terry Carroll
On Thu, 15 Feb 2007, Bill Campbell wrote:

> Having the Reply-To: to the original poster minimizes the probability of
> somebody sending mail to a list that was intended for the original poster
> (which may be private).  

Well, no.  It minimizes the probability of someone sending mail to a list.  

It equally minimizes that probability, regardless of whether the mail was 
intended to go to the list or privately to the original poster.

Most replies to this list are intended to go to the list.  At least a 
couple times a week we see messages from one of the more helpful tutors 
saying "please reply to the list, not just to me."  Just yesterday, I 
received an email in reply to one of my messages that was intended to 
assist the person I had replied to.  The intended recepient never got the 
email, because the sender, no doubt relying on the default, did not reply 
to the list.

Having reply-to go to the list is having it go to the most commonly 
preferred recipient.

So, minimizing the probability that the mail will go to the list, when 
most mail is intended to go to the list, is, I think, a Bad Thing.  Not 
that Bad a Thing, in the grand scheme of things, but a Bad Thing 
nonetheless.

> The only advantage of having it set to the list is it makes it easier
> for lazy people to send nonsense to hundreds of people.

That's way out of line.  The advantage of having it go to the list is to
make the default coincide with the usual intent; and that's what defaults
are for.

This is true regardless of whether the replying party is "lazy" or not;  
and regardless of whether the replying post is "nonsense" or not.

As I said, I have no particular dog in this fight.  The list uses a 
reply-to mechanism that I don't think makes sense, so I fixed it for 
myself with procmail.  But it's pretty arrogant to think that the divide 
of opinion on here is not a reasonable one, and that anyone who doesn't 
agree with your position must be lazy or writing nonsense.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor