Re: [Tutor] group txt files by month

2012-04-03 Thread Alan Gauld

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


Re: [Tutor] New to Python programing

2012-04-03 Thread Wayne Werner

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
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] breeds of Python .....

2012-04-03 Thread Wayne Werner

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
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] New to Python programing

2012-04-03 Thread Cranky Frankie
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
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New to Python programing

2012-04-03 Thread Christian Witts

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
//
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New to Python programing

2012-04-03 Thread Cranky Frankie
On Tue, Apr 3, 2012 at 10:09 AM, Christian Witts  wrote:

> Are you possibly thinking of the Khan Academy [1] ?
>
> [1] http://www.khanacademy.org/

Yes, that was it, thanks.


-- 
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
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Open source projects build using Python

2012-04-03 Thread Simon Yan
Dear All,

I've been working on Python for a while but haven't got any chance to work
on any projects yet. I've spent most of my time reading codes. (I know this
is bad when you want to actually learn a programming language)
It would be a better idea that I can start to join an open source projects
that is built with Python instead of starting up a new project. (I have no
good ideas at this moment anyways) I know there are lots of projects which
I can work on, but just wanted to hear some recommendations what are the
ones good for a long time Python "reader"?

-- 
Regards,
YeeYaa (Simon Yan)

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


[Tutor] Question about login=''.join(choice(lc) for j in range(llen))

2012-04-03 Thread Khalid Al-Ghamdi
Hi,

The following code tries to generate some dummy data for regex exercises.
My question is in reference the line before last:

dom="".join(choice(lc) for j in range (dlen))

how does the interpreter know what "j" is supposed to refer to when it was
not mentioned prior?


from random import randrange, choice
from string import ascii_lowercase as lc
from sys import maxsize
from time import ctime

tlds = ('com', 'edu', 'net', 'org', 'gov')

for i in range(randrange(5,11)):
dtint=randrange(maxsize)#pick a random number to use to generate
random date in next line
dtstr=ctime(dtint)  #date string
llen=randrange(4,8) #login is shorter
login=''.join(choice(lc) for j in range(llen))
dlen=randrange(llen,13) #domain is longer
dom="".join(choice(lc) for j in range (dlen))

print('{}::{}@{}.{}::{}-{}-{}'.format(dtstr,login,dom,choice(tlds),dtint,llen,dlen))
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question about login=''.join(choice(lc) for j in range(llen))

2012-04-03 Thread Emile van Sebille

On 4/3/2012 7:54 AM Khalid Al-Ghamdi said...

Hi,

The following code tries to generate some dummy data for regex
exercises. My question is in reference the line before last:

 dom="".join(choice(lc) for j in range (dlen))

how does the interpreter know what "j" is supposed to refer to when it
was not mentioned prior?



Prior value or not, j is the loop variable that steps over range(dlen) 
and refers to the numbers 0 to dlen-1 in turn.


Did you mean to ask something about the code below as well?

Emile





from random import randrange, choice
from string import ascii_lowercase as lc
from sys import maxsize
from time import ctime

tlds = ('com', 'edu', 'net', 'org', 'gov')

for i in range(randrange(5,11)):
 dtint=randrange(maxsize)#pick a random number to use to
generate random date in next line
 dtstr=ctime(dtint)  #date string
 llen=randrange(4,8) #login is shorter
 login=''.join(choice(lc) for j in range(llen))
 dlen=randrange(llen,13) #domain is longer
 dom="".join(choice(lc) for j in range (dlen))

print('{}::{}@{}.{}::{}-{}-{}'.format(dtstr,login,dom,choice(tlds),dtint,llen,dlen))



___
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


Re: [Tutor] Open source projects build using Python

2012-04-03 Thread bob gailer

On 4/3/2012 10:45 AM, Simon Yan wrote:

Dear All,

I've been working on Python for a while but haven't got any chance to 
work on any projects yet. I've spent most of my time reading codes. (I 
know this is bad when you want to actually learn a programming language)
It would be a better idea that I can start to join an open source 
projects that is built with Python instead of starting up a new 
project. (I have no good ideas at this moment anyways) I know there 
are lots of projects which I can work on, but just wanted to hear some 
recommendations what are the ones good for a long time Python "reader"?


I just sent a reply too a potential user of my fledgling project. Read 
and see if you are inspired.
 reply 
--

On 4/2/2012 5:23 PM, Alexander Todorov wrote:

Hello folks,
I'm looking for a stream based/event based parser utilities which I 
can use to build my application.


All I managed to find is related to SAX and XML but I will not be 
parsing XML documents. As an example there is a POD parser for Perl 
which behaves like a SAX parser:

https://metacpan.org/module/Pod::Parser


I'm looking for something similar in Python.

I will be parsing source code in various programming languages and 
need to be able to identify when a class definition starts, when 
function definition starts, etc.


If possible I'd prefer to have a base module which does the hard work 
and then small configuration modules for the various languages.


Can you point me to some relevant modules/docs?
Under development right now is an open-source project - Python Pipelines 
- a utility to do (amongst many other tasks) what you want.
With Pipelines you specify the source(s) and destination(s) of data and 
the various filters and transforms you want done to the data using a 
fairly straightforward language.


In your case (for starters) pipe ">functions.txt" would read all the records (linies) in source.py, 
select just those containing 'def:' and write them to functions.txt. 
There is much more that can be accomplished.
--- end reply 
---


If this sparks your interest I will send you the developer's guide.

--
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] Open source projects build using Python

2012-04-03 Thread Alan Gauld

On 03/04/12 15:45, Simon Yan wrote:


projects which I can work on, but just wanted to hear some
recommendations what are the ones good for a long time Python "reader"?


One that interests you.
I might think that a system to control the irrigation of my hydroponics 
garden is fascinating but you might find it boring compared to one that 
translated Norse runes into English...


You will always be more motivated working on something that interests 
you and for which you have a personal use. (Or alternatively, one for 
which you get paid large sums of money! :-)


Do a search on SourceForge and Google and see what comes up.
Look for signs of activity otherwise you might wind up owning the 
project! Start with documenting, testing or bug fixing.


--
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] Question about login=''.join(choice(lc) for j in range(llen))

2012-04-03 Thread Alan Gauld

On 03/04/12 15:54, Khalid Al-Ghamdi wrote:


 dom="".join(choice(lc) for j in range (dlen))

how does the interpreter know what "j" is supposed to refer to when it
was not mentioned prior?


In Python variables are defined by using them.

In the code below you have i used in a for loop, even though not 
mentioned before. j is similarly being used in the generator expression 
for loop:


choice(lc) for j in range (dlen)

unwraps to:

dummy = []
for j in range(dlen):
   dummy.append(choice(lc))

Which effectively creates a list of dlen choice items.



from random import randrange, choice
from string import ascii_lowercase as lc
from sys import maxsize
from time import ctime

tlds = ('com', 'edu', 'net', 'org', 'gov')

for i in range(randrange(5,11)):
 dtint=randrange(maxsize)#pick a random number to use to


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] New to Python programing

2012-04-03 Thread Brad Hudson
>> Are you possibly thinking of the Khan Academy [1] ?
>>
>> [1] http://www.khanacademy.org/

If you're interested in free courses, MIT also has free programming
courses (done in Python) via their OpenCourseWare and will be
expanding this to MITx in the near future.

OpenCourseWare - Intro to Computer Science & Programming (Python
based) located here:
http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00sc-introduction-to-computer-science-and-programming-spring-2011/index.htm

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


Re: [Tutor] Open source projects build using Python

2012-04-03 Thread Mark Lawrence

On 03/04/2012 18:22, Alan Gauld wrote:

On 03/04/12 15:45, Simon Yan wrote:

Do a search on SourceForge and Google and see what comes up.



Hopefully codeplex.com amongst others.

--
Cheers.

Mark Lawrence.

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


Re: [Tutor] Question about login=''.join(choice(lc) for j in range(llen))

2012-04-03 Thread Peter Otten
Alan Gauld wrote:

> On 03/04/12 15:54, Khalid Al-Ghamdi wrote:
> 
>>  dom="".join(choice(lc) for j in range (dlen))
>>
>> how does the interpreter know what "j" is supposed to refer to when it
>> was not mentioned prior?
> 
> In Python variables are defined by using them.
> 
> In the code below you have i used in a for loop, even though not
> mentioned before. j is similarly being used in the generator expression
> for loop:
> 
> choice(lc) for j in range (dlen)
> 
> unwraps to:
> 
> dummy = []
> for j in range(dlen):
> dummy.append(choice(lc))

An interesting aspect of these "generator expressions" is that they are 
"lazy", they deliver only as many items as necessary.

>>> numbers = (n for n in range(1000))
>>> next(numbers)
0
>>> next(numbers)
1
>>> any(n>10 for n in numbers)
True
>>> next(numbers)
12
>>> any(n<10 for n in numbers)
False
>>> next(numbers)
Traceback (most recent call last):
  File "", line 1, in 
StopIteration

The StopIteration hints that we have consumed all numbers. We were already 
at 13 when we asked for a number < 10; therefore the complete rest from 13 
to 999 was scanned in vain.

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


[Tutor] generators

2012-04-03 Thread mike jackson
I am trying understand python and have done fairly well, So for it has been 
easy to learn and is concise.  However I seem to not quite understand the use 
of a generator over a function(I am familiar with functions [other languages 
and math]).  To me (excepting obvious syntax differences) a generator is a 
function.  Why should I use a generator instead of a function or vice versa?  
Is perhaps specfic uses it was created to handle?  A great web page with good 
examples would be nice.  Of course if you can sum it up rather easy then by all 
means go ahead.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] generators

2012-04-03 Thread Abhishek Pratap
Hey Mike

The following link should help you. http://www.dabeaz.com/generators/
. Cool slide deck with examples from David Beazley's  explanation of
generators.


-A




On Tue, Apr 3, 2012 at 11:38 AM, mike jackson  wrote:
> I am trying understand python and have done fairly well, So for it has been 
> easy to learn and is concise.  However I seem to not quite understand the use 
> of a generator over a function(I am familiar with functions [other languages 
> and math]).  To me (excepting obvious syntax differences) a generator is a 
> function.  Why should I use a generator instead of a function or vice versa?  
> Is perhaps specfic uses it was created to handle?  A great web page with good 
> examples would be nice.  Of course if you can sum it up rather easy then by 
> all means go ahead.
> ___
> 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


Re: [Tutor] New to Python programing

2012-04-03 Thread wesley chun
a couple of other sources of video learning (DISCLAIMER: the 1st is
from my employer, and the 2nd is from me -- the intention is to
provide alternatives not shameless self-promotion so please don't take
it that way!):

1. Google offers an internal Python training class to its employees.
it's a 2-day course designed to teach existing programmers how to code
in Python, covering syntax, data structures, etc. (it's not deep and
thorough like the course i teach publicly but it may be just what you
need.)

i volunteer to deliver it a couple of times a year. anyway, you can
get all the course contents, exercises, and a lively delivery by my
colleague Nick Parlante (recorded a few years ago) across 7 videos
which span both days here:
http://code.google.com/edu/languages/google-python-class

2. a few years ago, i was asked to do a video version of my public
course blended with material from the "Core Python Programming" book.
the primary target audience includes existing programmers who need to
learn Python (2.x & 3.x) quickly and comprehensively via video
lectures (as opposed to the "show-me-do" style of onscreen hacking --
which is *also* a viable way of learning but just not for everyone).

some people prefer the lecture-style, so if you do, then you may wish
to consider it. i made the mistake of not being more public about this
early on, hence some of the not-so-great Amazon reviews. :P anyway, if
you're interested, you can get a free video clip here:
http://www.informit.com/store/product.aspx?isbn=9780137143412. (the
editors left some of my bleeping bloopers in the DVD, so it may be
entertaining to you at my expense.) another free preview of my
teaching style (if you want to learn about Python Generators) can be
found at http://cyberwebconsulting.com

cheers,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"A computer never does what you want... only what you tell it."
    wesley chun : wescpy at gmail : @wescpy/+wescpy
    Python training & consulting : CyberwebConsulting.com
    "Core Python" books : CorePython.com
    Python blog: wescpy.blogspot.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] generators

2012-04-03 Thread Joel Goldstick
On Tue, Apr 3, 2012 at 2:38 PM, mike jackson  wrote:
> I am trying understand python and have done fairly well, So for it has been 
> easy to learn and is concise.  However I seem to not quite understand the use 
> of a generator over a function(I am familiar with functions [other languages 
> and math]).  To me (excepting obvious syntax differences) a generator is a 
> function.  Why should I use a generator instead of a function or vice versa?  
> Is perhaps specfic uses it was created to handle?  A great web page with good 
> examples would be nice.  Of course if you can sum it up rather easy then by 
> all means go ahead.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

A generator function is a special kind of function that uses the
'yield' statement to return a value.  The next time the function is
called, it starts up from the place following the yield statement.
They are useful in producing the next value in a computed sequence of
values without having to compute the whole sequence at one go.

Here is a great tutorial about things you can do with generators:
http://www.dabeaz.com/generators/

Here is some simple code with results below

#! /usr/bin/env python
""" generator vs normal function"""
""" a 'Normal' function"""
def n(r):
v = []
for i in range(r):
  v.append(i*2)
return v

""" A generator function"""
def g(r):
for i in range(r):
yield i*2

print n(3)

for i in g(3):
print i

generated_list = [i for i in g(3)]
print generated_list

[0, 2, 4]
0
2
4
[0, 2, 4]

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


Re: [Tutor] Question about login=''.join(choice(lc) for j in range(llen))

2012-04-03 Thread wesley chun
On Tue, Apr 3, 2012 at 10:50 AM, Peter Otten <__pete...@web.de> wrote:
> Alan Gauld wrote:
>> On 03/04/12 15:54, Khalid Al-Ghamdi wrote:
>>
>>>      dom="".join(choice(lc) for j in range (dlen))
>>>
>>> how does the interpreter know what "j" is supposed to refer to when it
>>> was not mentioned prior?


+1 everyone else's replies so far. i'll add the following: you create
variables by assigning things to them. in this example, no prior code
used the variable 'x':

>>> x = 10
>>> print x
10

similarly, when used in a for-loop, it's like you had an "invisible"
assignment at the "top" of the loop. here's an example:

>>> for i in range(5):
...  print i
...
0
1
2
3
4
>>> print i
4

notice that the 'i' variable is still there even after the loop has
ended. it's as if you did the following:

>>> i = 0
>>> print i
0
>>> i = 1
:
>>> i = 4
>>> print i  # 1st time, part of the "loop"
4
>>> print i  # 2nd time, "outside" of the loop
4

hope this helps!
--wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"A computer never does what you want... only what you tell it."
    wesley chun : wescpy at gmail : @wescpy/+wescpy
    Python training & consulting : CyberwebConsulting.com
    "Core Python" books : CorePython.com
    Python blog: wescpy.blogspot.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] generators

2012-04-03 Thread wesley chun
> On Tue, Apr 3, 2012 at 2:38 PM, mike jackson  wrote:
> I am trying understand python and have done fairly well, So for it has been 
> easy to learn and is concise.  However I seem to not quite understand the use 
> of a generator over a function(I am familiar with functions [other languages 
> and math]).  To me (excepting obvious syntax differences) a generator is a 
> function.  Why should I use a generator instead of a function or vice versa?  
> Is perhaps specfic uses it was created to handle?  A great web page with good 
> examples would be nice.  Of course if you can sum it up rather easy then by 
> all means go ahead.


dave beazley's lectures are *awesome*, and even more so if you can
attend them in-person. below are my comments on generators off the top
of my head:

1. syntactically, generators are merely functions with one or more
"yield" statements/expressions

2. users of generators will see them primarily as "advanced"
iterators, because they yield individual values until such an iterator
has been exhausted (StopIteration).

3. creators of generators will see them more like functions that you
can pause, "return" some intermediate value, then be resumable/resumed
later. the C language has the concept of a "static function" where
variables can maintain their values across function calls. while being
"nice," it's not nearly as powerful as being able to save the values
*and* the entire state of execution at the time the function is paused
then resume right where it left off later, hence the comparisons with
co-routines (which are even more independent threads of execution).

4. "generator expressions" are the lazy evaluation form of list
comprehensions, and better for memory because of that. they'll behave
just like generators but can be defined easily on a single line, just
like normal listcomps.

5. i made a quick 5-minute video introducing Python developers to
generators... it's a very ad hoc and informal session during one of my
Python courses that a student recorded. if interested in viewing it,
you can find it half-way down http://cyberwebconsulting.com

hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"A computer never does what you want... only what you tell it."
    wesley chun : wescpy at gmail : @wescpy/+wescpy
    Python training & consulting : http://CyberwebConsulting.com
    "Core Python" books : http://CorePython.com
    Python blog: http://wescpy.blogspot.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Open source projects build using Python

2012-04-03 Thread Simon Yan
On Wed, Apr 4, 2012 at 1:41 AM, Mark Lawrence wrote:

> On 03/04/2012 18:22, Alan Gauld wrote:
>
>> On 03/04/12 15:45, Simon Yan wrote:
>>
>> Do a search on SourceForge and Google and see what comes up.
>>
>>
> Hopefully codeplex.com amongst others.
>
>
Hey Guys,

Thank you all for the good suggestions. I'm gonna make some research and
look around to find the sweet spot.


>  --
> Cheers.
>
> Mark Lawrence.
>
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor
>



-- 
Regards,
YeeYaa (Simon Yan)

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