Re: [Tutor] generators

2012-04-04 Thread bob gailer

To Joel's and Wesley's valuable comments I add:

Calling a generator function returns a /generator object/.

>>> def x(n):
...  for i in range(n): yield i
...
>>> y = x(3)
>>> print y


A generator object can be used instead of some other "iterable" (e.g.) 
in for statements.

>>> for i in y:print i
0
1
2

x in this case is equivalent to xrange() with exactly 1 argument.

There is more that can be said regarding x.next(). x.send(), raise 
StopIteration but I've said enough for now.


--
Bob Gailer
919-636-4239
Chapel Hill NC

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 98, Issue 7

2012-04-04 Thread Walter Luna
Dear Python friends:

Thank you for the rapid response, I researched the information you sent me
and it has a lot of resources that I can use. I will use some of those
resources and continue with my learning journey, I am sure that I will have
a lot of questions but I feel confident that I have your support.

Best regards

Walter Luna

On Tue, Apr 3, 2012 at 7:54 AM,  wrote:

> Send Tutor mailing list submissions to
>tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>tutor-requ...@python.org
>
> You can reach the person managing the list at
>tutor-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>   1. Re: New to Python programing (Wayne Werner)
>   2. Re: breeds of Python . (Wayne Werner)
>   3. New to Python programing (Cranky Frankie)
>   4. Re: New to Python programing (Christian Witts)
>   5. Re: New to Python programing (Cranky Frankie)
>   6. Open source projects build using Python (Simon Yan)
>   7. Question about login=''.join(choice(lc) for j in  range(llen))
>  (Khalid Al-Ghamdi)
>
>
> --
>
> Message: 1
> Date: Tue, 3 Apr 2012 05:02:13 -0500 (CDT)
> From: Wayne Werner 
> To: wesley chun 
> Cc: "tutor@python.org" , Walter Luna
>
> Subject: Re: [Tutor] New to Python programing
> Message-ID: 
> Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
>
> On Mon, 2 Apr 2012, wesley chun wrote:
>
> > greetings walter, and welcome to the Python family!
> 
> > as far as books go, the best way to learn Python is by writing games.
> > this is an approach that works both with children as well as adults.
> > there are several excellent books that can help you with this regard:
>
> There is another book that I didn't notice mentioned: Game Programming:
> The L line, the express
> line to learning.
>
> The book is unfortunately named because it makes no mention of Python, but
> it's
> quite a good book for learning both programming and Python... and games!
>
> Good luck and welcome to Python!
> -Wayne Werner
>
>
> --
>
> Message: 2
> Date: Tue, 3 Apr 2012 05:12:38 -0500 (CDT)
> From: Wayne Werner 
> To: Modulok 
> Cc: tutor@python.org
> Subject: Re: [Tutor] breeds of Python .
> Message-ID: 
> Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
>
> On Sat, 31 Mar 2012, Modulok wrote:
> > If you're just starting out, go with 3.x. If you have a need for some
> third
> > party modules that aren't yet available for 3.x, you'll have to stick
> with 2.x.
>
> For a handy list, check out the Python3 Wall of Shame (soon to be
> superpowers?)
> http://python3wos.appspot.com/
>
> HTH,
> Wayne
>
>
> --
>
> Message: 3
> Date: Tue, 3 Apr 2012 09:50:01 -0400
> From: Cranky Frankie 
> To: tutor@python.org
> Subject: [Tutor] New to Python programing
> Message-ID:
> >
> Content-Type: text/plain; charset=windows-1252
>
> Another resourse for learning to program is YouTube. They just had a
> segment on "60 Minutes" about a guy who does all kinds of well
> regarded free courses on-line, unfortunately I can't remberber the
> URL. I've viewed several Stanford University programming courses, and
> there are many Python specific vidoes there as well. Just something
> else to check out.
>
> --
> Frank L. "Cranky Frankie" Palmeri
> Risible Riding Raconteur & Writer
> ?The problem with quotes on the Internet is that
> it is often difficult to verify their authenticity.?
> - Abraham Lincoln
>
>
> --
>
> Message: 4
> Date: Tue, 03 Apr 2012 16:09:21 +0200
> From: Christian Witts 
> To: Cranky Frankie 
> Cc: tutor@python.org
> Subject: Re: [Tutor] New to Python programing
> Message-ID: <4f7b0491.6040...@compuscan.co.za>
> Content-Type: text/plain; charset="windows-1252"; Format="flowed"
>
> On 2012/04/03 03:50 PM, Cranky Frankie wrote:
> > Another resourse for learning to program is YouTube. They just had a
> > segment on "60 Minutes" about a guy who does all kinds of well
> > regarded free courses on-line, unfortunately I can't remberber the
> > URL. I've viewed several Stanford University programming courses, and
> > there are many Python specific vidoes there as well. Just something
> > else to check out.
> >
> Are you possibly thinking of the Khan Academy [1] ?
>
> [1] http://www.khanacademy.org/
> --
>
> Christian Witts
> Python Developer
> //
> -- next part --
> An HTML attachment was scrubbed...
> URL: <
> http://mail.python.org/pipermail/tutor/attachments/20120403/68e50894/attachment-0001.html
> >
>
> --
>
> Message: 5
> Date: Tue, 3 Apr 2012 10:12:36 -0400
> From: Cranky Frankie 
> To: tutor@python.org
> Subject: Re: [Tutor] N

[Tutor] cPickle/pickle help

2012-04-04 Thread b. nyec
Hello, 

I'm not sure if this is the correct list to post this on, but i was wondering i 
someone could help me. I'm wondering if there exists a pickler example written 
in C ? I understand the cPickle module was written in C, but looking at it 
seems daunting to create sample code from it. I found a post on this list here: 
http://mail.python.org/pipermail//tutor/2011-September/085414.html that shows 
an example of pickling data to disk. I'm wondering if that's pickle or cPickle 
(protocol version?) ?? What i'm trying to do is write a client in C that will 
send pickled data to a server written in python for unpicking over TCP. I'm 
still learning this stuff (pickle/serialization) as i go (i have zero knowledge 
of python), so apologies if i'm not making any sense as i've had trouble 
finding help on other places when explaining what i'm trying to accomplish. If 
this is off topic, feel free to e-mail me privately and i could explain in more 
detail without adding noise to
 this list. 

Thanks for any help. 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 98, Issue 7

2012-04-04 Thread Alan Gauld

On 04/04/12 17:35, Walter Luna wrote:

Dear Python friends:

Thank you for the rapid response, I researched the information you sent
me and it has a lot of resources that I can use.


You are welcome however, when posting to the list in future, please do 
not reply to a digest message without:

- change the subject to something meaningful (see quoted text below)
- delete all content not directly relevant to your post.

Some people pay by the byte, others are too busy to want to scan through 
a long post of mails they have already seen searching for new/relevant 
information.


Finally, it is preferred if you post comments *under* the context rather 
than at the top of the message. This again makes it easier for readers 
to understand the context.


Regards,

Alan G.
Tutor List moderator




On Tue, Apr 3, 2012 at 7:54 AM, mailto:tutor-requ...@python.org>> wrote:

Send Tutor mailing list submissions to
tutor@python.org 


...


When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."




--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] cPickle/pickle help

2012-04-04 Thread Alan Gauld

On 04/04/12 18:25, b. nyec wrote:


I'm not sure if this is the correct list to post this on,


No its not, this list is for folks learning Python the language.


but i was wondering i someone could help me.


You might get lucky here but are more likely to find responses
on the main Python mailing list/newsgroup:

comp.lang.python

> I'm wondering if there exists a pickler example written in C ?

The pickle module is intended to be used in Python rather than from C.
The examples are therefore written from a Python users standpoint.
However it is possible to embed Python into your C program and there are 
separate documents to describe how to do that. That might be the easiest 
way to approach this, but I' ve never tried so don't know.



I understand the cPickle module was written in C, but looking


Many Python modules are written in C but they are all intended to be 
used from within Python. Reading the code could show you how to 
read/write the various data types, but you would need to replicate the C 
functions in the module in your code.



I found a post on this list here: 
http://mail.python.org/pipermail//tutor/2011-September/085414.html

> that shows an example of pickling data to disk.

It doesn't matter much since the Python code is the same, it just runs 
faster with cPickle. The only difference is whether you start with


import pickle
or
import cPickle

I recommend you try the main list.
And the embedding Python option is worth investigating:

http://docs.python.org/extending/embedding.html

HTH,
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] cPickle/pickle help

2012-04-04 Thread Mark Lawrence

On 04/04/2012 18:25, b. nyec wrote:

Hello,

I'm not sure if this is the correct list to post this on, but i was wondering i 
someone could help me. I'm wondering if there exists a pickler example written 
in C ? I understand the cPickle module was written in C, but looking at it 
seems daunting to create sample code from it. I found a post on this list here: 
http://mail.python.org/pipermail//tutor/2011-September/085414.html that shows 
an example of pickling data to disk. I'm wondering if that's pickle or cPickle 
(protocol version?) ?? What i'm trying to do is write a client in C that will 
send pickled data to a server written in python for unpicking over TCP. I'm 
still learning this stuff (pickle/serialization) as i go (i have zero knowledge 
of python), so apologies if i'm not making any sense as i've had trouble 
finding help on other
  places when explaining what i'm trying to accomplish. If this is off topic, 
feel free to e-mail me privately and i could explain in more detail without 
adding noise to
  this list.

Thanks for any help.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



You're probably better off asking on comp.lang.python but the advice 
will almost certainly be don't do it see e.g. 
http://www.velocityreviews.com/forums/t944852-re-re-advise-of-programming-one-of-my-first-programs.html


--
Cheers.

Mark Lawrence.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to reply - best practice.

2012-04-04 Thread bob gailer

On 4/4/2012 12:35 PM, Walter Luna wrote:

Dear Python friends:

Thank you for the rapid response, I researched the information you 
sent me and it has a lot of resources that I can use. I will use some 
of those resources and continue with my learning journey, I am sure 
that I will have a lot of questions but I feel confident that I have 
your support.


Glad we could help.

To make our lives easier please only include relevant text, and make the 
subject also relevant.


--
Bob Gailer
919-636-4239
Chapel Hill NC

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] cPickle/pickle help

2012-04-04 Thread b. nyec


--- On Wed, 4/4/12, Mark Lawrence  wrote:

> From: Mark Lawrence 
> Subject: Re: [Tutor] cPickle/pickle help
> To: tutor@python.org
> Date: Wednesday, April 4, 2012, 1:16 PM
> On 04/04/2012 18:25, b. nyec wrote:
> > Hello,
> >
> > I'm not sure if this is the correct list to post this
> on, but i was wondering i someone could help me. I'm
> wondering if there exists a pickler example written in C ? I
> understand the cPickle module was written in C, but looking
> at it seems daunting to create sample code from it. I found
> a post on this list here: 
> http://mail.python.org/pipermail//tutor/2011-September/085414.html
> that shows an example of pickling data to disk. I'm
> wondering if that's pickle or cPickle (protocol version?) ??
> What i'm trying to do is write a client in C that will send
> pickled data to a server written in python for unpicking
> over TCP. I'm still learning this stuff
> (pickle/serialization) as i go (i have zero knowledge of
> python), so apologies if i'm not making any sense as i've
> had trouble finding help on other
> >   places when explaining what i'm trying
> to accomplish. If this is off topic, feel free to e-mail me
> privately and i could explain in more detail without adding
> noise to
> >   this list.
> >
> > Thanks for any help.
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
> >
> 
> You're probably better off asking on comp.lang.python but
> the advice 
> will almost certainly be don't do it see e.g. 
> http://www.velocityreviews.com/forums/t944852-re-re-advise-of-programming-one-of-my-first-programs.html
> 
> -- 
> Cheers.
> 
> Mark Lawrence.
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 

Yep I'm fully aware of the ol "Validate user input" security 101 with pickle. 
:) Looking around the last few days for help, is point more and more to a 
project i didn;t quite intend on taking up. Oh well. 
Thanks. 


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] group txt files by month

2012-04-04 Thread questions anon
thanks for responding.
Glob and os.walk will work but I would need to type up a separate command
for each month of each year and that doesn't seem very efficient. Is there
a way to make it go through and group txt files with similar filenames
e.g something like:
if fname.endswith('.txt')and fname[0:7]==fname[0:7]
e.g. r20110101.txt and r20110102.txt should go together but r20110601
should not.
thanks

On Tue, Apr 3, 2012 at 4:59 PM, Alan Gauld wrote:

> On 03/04/12 04:59, questions anon wrote:
>
>  I have a list of txt files that contain daily rainfall for many years.
>> They are set out like:
>> r20110101.txt
>> r20110102.txt
>> r20110103.txt
>> and so on for each day for many years.
>>
>> MainFolder=r"E:/Rainfalldata/"
>> outputFolder=r"E:/test/"
>> for (path, dirs, files) in os.walk(MainFolder):
>>
>
> If the files are all in a single folder you might be better using
> glob.glob() rather than os.walk. You can pass a filename pattern
> like *.txt to glob(). This might make it easier to group the
> files by year... 2010*.txt for example.
>
> You can do it with walk too its just a bit more effort. But if the files
> are in multiple folders walk() is probably  better.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] __class__.__name__ for literal integer causes SyntaxError

2012-04-04 Thread Tim Johnson
See the following console session:
>>> 4.6.__class__.__name__
'float'
>>> 6.__class__.__name__
  File "", line 1
6.__class__.__name__
  ^
SyntaxError: invalid syntax
>>> x = 6
>>> x.__class__.__name__
'int'
>>> "me".__class__.__name__
'str'
I note that the reference to '__class__.__name__' for string and
float literals is executed, but that there is a SyntaxError for that
same reference of a 'int' literal.

I'd welcome comments, explanations or URLs to discussions.
thanks
-- 
Tim 
tim at tee jay forty nine dot com or akwebsoft dot com
http://www.akwebsoft.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] __class__.__name__ for literal integer causes SyntaxError

2012-04-04 Thread Emile van Sebille

On 4/4/2012 6:27 PM Tim Johnson said...

See the following console session:

4.6.__class__.__name__


The first decimal is considered to be part of the float literal here...



'float'

6.__class__.__name__


... _and_ here...


   File "", line 1
 6.__class__.__name__
   ^
SyntaxError: invalid syntax


... which explains the error -- the float value is improper.


x = 6
x.__class__.__name__

'int'

"me".__class__.__name__

'str'
I note that the reference to '__class__.__name__' for string and
float literals is executed, but that there is a SyntaxError for that
same reference of a 'int' literal.

I'd welcome comments, explanations or URLs to discussions.
thanks


Try

>>> (6).__class__.__name__
'int'
>>>

HTH,

Emile

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] group txt files by month

2012-04-04 Thread questions anon
I have been able to write up what I want to do (using glob) but I am not
sure how to loop it or simplify it to make the script more efficient.
I am currently:
-grouping the same months in a year using glob
-opening the files in a group and combining the data using a list
-finding max, min etc for the list and printing it

I need to do this for many years and therefore many months so really need a
way to make this more efficient.
Any feedback will be greatly appreciated

MainFolder=r"E:/rainfall-2011/"
OutputFolder=r"E:/test_out/"
r201101=glob.glob(MainFolder+"r201101??.txt")
r201102=glob.glob(MainFolder+"r201102??.txt")
r201103=glob.glob(MainFolder+"r201103??.txt")

rain201101=[]
rain201102=[]
rain201103=[]
monthlyrainfall=[]

for ifile in r201101:
f=np.genfromtxt(ifile, skip_header=6)
rain201101.append(f)

for ifile in r201102:
f=np.genfromtxt(ifile, skip_header=6)
rain201102.append(f)

for ifile in r201103:
f=np.genfromtxt(ifile, skip_header=6)
rain201103.append(f)

print "jan", np.max(rain201101), np.min(rain201101), np.mean(rain201101),
np.median(rain201101), np.std(rain201101)
print "feb", np.max(rain201102), np.min(rain201102), np.mean(rain201102),
np.median(rain201102), np.std(rain201102)
print "mar", np.max(rain201103), np.min(rain201103), np.mean(rain201103),
np.median(rain201103), np.std(rain201103)


On Thu, Apr 5, 2012 at 11:11 AM, questions anon wrote:

> thanks for responding.
> Glob and os.walk will work but I would need to type up a separate command
> for each month of each year and that doesn't seem very efficient. Is there
> a way to make it go through and group txt files with similar filenames
> e.g something like:
> if fname.endswith('.txt')and fname[0:7]==fname[0:7]
> e.g. r20110101.txt and r20110102.txt should go together but r20110601
> should not.
> thanks
>
>
> On Tue, Apr 3, 2012 at 4:59 PM, Alan Gauld wrote:
>
>> On 03/04/12 04:59, questions anon wrote:
>>
>>  I have a list of txt files that contain daily rainfall for many years.
>>> They are set out like:
>>> r20110101.txt
>>> r20110102.txt
>>> r20110103.txt
>>> and so on for each day for many years.
>>>
>>> MainFolder=r"E:/Rainfalldata/"
>>> outputFolder=r"E:/test/"
>>> for (path, dirs, files) in os.walk(MainFolder):
>>>
>>
>> If the files are all in a single folder you might be better using
>> glob.glob() rather than os.walk. You can pass a filename pattern
>> like *.txt to glob(). This might make it easier to group the
>> files by year... 2010*.txt for example.
>>
>> You can do it with walk too its just a bit more effort. But if the files
>> are in multiple folders walk() is probably  better.
>>
>> --
>> Alan G
>> Author of the Learn to Program web site
>> http://www.alan-g.me.uk/
>>
>> __**_
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/**mailman/listinfo/tutor
>>
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Running scripts at login

2012-04-04 Thread Michael Lewis
Hi everyone,

I am researching how to automatically run some of my scripts after I log
into my Windows machine. I don't want to have to manually run the script or
setup a windows task.

I'd like to have a piece of code that I can insert into my script that will
allow it to run after I login.

I found the piece by Alan G.; however, it deals with linux and I can't seem
to find a good source for Windows machine:

http://mail.python.org/pipermail/tutor/2010-July/077319.html

Thanks for the help.

-- 
Michael J. Lewis
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor