Re: [Tutor] using datetime and calculating hourly average

2009-07-08 Thread John [H2O]

Sanders,

The problem is I don't want date, I want the date AND hour, just not
minutes.

As for the comparison, in numpy here's what happens when I change the way I
construct the where statements:

--> 196 ind = np.where( (t1 < Y[:,0] < t2) ) #same result
with/without inner parens
197 screen_vals = Y[ind,1][0]
198 #print 'X time: %s' % t1

TypeError: can't compare datetime.datetime to numpy.ndarray


OR trying the 'and' method:

--> 196 ind = np.where( (Y[:,0]>t1) and (Y[:,0]http://www.nabble.com/using-datetime-and-calculating-hourly-average-tp24370537p24388708.html
Sent from the Python - tutor mailing list archive at Nabble.com.

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


[Tutor] Quick question regarding Parsing a Delimited string

2009-07-08 Thread Garry Bettle
Hi,

I've been programming for over 20 yrs, but only the last few in python
and then only in dribs and drabs.

I'm having a difficult time parsing a delimited string.

e.g.

100657641~GBP~ACTIVE~0~1~~true~5.0~1247065352508~:
3818854~0~24104.08~4.5~~22.1~false|4.4~241.67~L~1~4.3~936.0~L~2~4.2~210.54~L~3~|4.5~19.16~B~1~4.6~214.27~B~2~4.7~802.13~B~3~:
3991404~1~19974.18~4.7~~21.7~false|4.6~133.01~L~1~4.5~124.83~L~2~4.4~319.33~L~3~|4.7~86.61~B~1~4.8~247.9~B~2~4.9~142.0~B~3~:
4031423~2~15503.56~6.6~~15.1~false|6.6~53.21~L~1~6.4~19.23~L~2~6.2~53.28~L~3~|6.8~41.23~B~1~7.0~145.04~B~2~7.2~37.23~B~3~

That is just a selection of the full string - and I've broken it up
for this email.  It's delimited by : and then by ~ and finally, in
some cases, | (a pipe).

If the string is called m, I thought I could create a list with
m.split(":").  I would like to then first of all find in this list the
entry beginning with e.g. 3991404.

I thought I could pop each item in the list and compare that seems
pretty long winded.

When the ItemFound is now =
'3991404~1~19974.18~4.7~~21.7~false|4.6~133.01~L~1~4.5~124.83~L~2~4.4~319.33~L~3~|4.7~86.61~B~1~4.8~247.9~B~2~4.9~142.0~B~3~:'

I would like to return the 3rd item delimited with ~, which in this case, is 4.7

Can anyone help?

Many thanks!

Cheers,

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


Re: [Tutor] Quick question regarding Parsing a Delimited string

2009-07-08 Thread Rich Lovely

On 8 Jul 2009, at 17:13, Garry Bettle  wrote:


Hi,

I've been programming for over 20 yrs, but only the last few in python
and then only in dribs and drabs.

I'm having a difficult time parsing a delimited string.

e.g.

100657641~GBP~ACTIVE~0~1~~true~5.0~1247065352508~:
3818854~0~24104.08~4.5~~22.1~false| 
4.4~241.67~L~1~4.3~936.0~L~2~4.2~210.54~L~3~| 
4.5~19.16~B~1~4.6~214.27~B~2~4.7~802.13~B~3~:
3991404~1~19974.18~4.7~~21.7~false| 
4.6~133.01~L~1~4.5~124.83~L~2~4.4~319.33~L~3~| 
4.7~86.61~B~1~4.8~247.9~B~2~4.9~142.0~B~3~:
4031423~2~15503.56~6.6~~15.1~false| 
6.6~53.21~L~1~6.4~19.23~L~2~6.2~53.28~L~3~| 
6.8~41.23~B~1~7.0~145.04~B~2~7.2~37.23~B~3~


That is just a selection of the full string - and I've broken it up
for this email.  It's delimited by : and then by ~ and finally, in
some cases, | (a pipe).

If the string is called m, I thought I could create a list with
m.split(":").  I would like to then first of all find in this list the
entry beginning with e.g. 3991404.

I thought I could pop each item in the list and compare that seems
pretty long winded.

When the ItemFound is now =
'3991404~1~19974.18~4.7~~21.7~false| 
4.6~133.01~L~1~4.5~124.83~L~2~4.4~319.33~L~3~| 
4.7~86.61~B~1~4.8~247.9~B~2~4.9~142.0~B~3~:'


I would like to return the 3rd item delimited with ~, which in this  
case, is 4.7


Can anyone help?

Many thanks!

Cheers,

Garry
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
I've been dealing with a similar problem myself, parsing input for  
project Euler. The way I did it was to map a split function onto the  
first list:


lst = map(lambda s: s.split("~"), m.split(":"))
You can get the same effect with a comprehension:

lst = [s.split("~") for s in m.split(":")]

You can then use a function like the following:

def find(term):
for i in lst:
if i[0] == term:
return i[3]

Of course, this assumes that you only want the first match, but it  
would be trivial to modify it to return all matches.


Does that help? If it doesn't solve the problem, I hope it will at  
least point you towards how to solve it.


If you really want to speed up the search, you could turn the list of  
lists into a dict, using the first value in each sublist as a key:


dct = dict((i[0], i[1:]) for i in lst)

Then you can access it using the normal dictionary interface.
dct["3991404"][3]

This will only return the last of any repeated values (previous ones  
will get overwritten during construction), so it really depends on the  
behaviour you want.

---
Richard "Roadie Rich" Lovely
Part of the JNP|UK Famille
www.theJNP.com

(Sent from my iPod - please allow me a few typos: it's a very small  
keyboard)

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


[Tutor] error message

2009-07-08 Thread Steven Buck
I'm running a for loop which returns an error message after the third
iteration (see out[4] at the bottom as evidence).  I don't understand the
error message.  Although I'll continue to do my own digging to debug, I
thought I'd give you all a shot.  Thanks, -steve

Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.
IPython 0.9.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help  -> Python's own help system.
object?   -> Details about 'object'. ?object also works, ?? prints more.
In [1]: import psid
In [2]: age = {}
In [3]: for i in range(len(psid.psid)):
   ...: age[(i)] = psid.psid[i][20]
   ...:
   ...:
---
error Traceback (most recent call last)
C:\Documents and Settings\Steve\ in ()
C:\Python26\lib\site-packages\StataTools.pyc in __getitem__(self, k)
 85 if self._file.tell() != loc:
 86 self._file.seek(loc)
---> 87 return self._next()
 88
 89 ### PyDTA private methods

C:\Python26\lib\site-packages\StataTools.pyc in _next(self)
167 else:
168 data[i] = self._unpack(typlist[i],
self._file.read(s
elf._col_size(i)))
169 return data
170 else:
--> 171 return map(lambda i: self._unpack(typlist[i],
self._file.rea
d(self._col_size(i))), range(self._header['nvar']))
C:\Python26\lib\site-packages\StataTools.pyc in (i)
167 else:
168 data[i] = self._unpack(typlist[i],
self._file.read(s
elf._col_size(i)))
169 return data
170 else:
--> 171 return map(lambda i: self._unpack(typlist[i],
self._file.rea
d(self._col_size(i))), range(self._header['nvar']))
C:\Python26\lib\site-packages\StataTools.pyc in _unpack(self, fmt, byt)
148
149 def _unpack(self, fmt, byt):
--> 150 d = unpack(self._header['byteorder']+fmt, byt)[0]
151 if fmt[-1] in self.MISSING_VALUES:
152 nmin, nmax = self.MISSING_VALUES[fmt[-1]]
error: unpack requires a string argument of length 1
In [4]: age
Out[4]: {0: 22, 1: 51, 2: 42}
In [5]:
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Quick question regarding Parsing a Delimited string

2009-07-08 Thread Kent Johnson
On Wed, Jul 8, 2009 at 12:13 PM, Garry Bettle wrote:
> Hi,
>
> I've been programming for over 20 yrs, but only the last few in python
> and then only in dribs and drabs.
>
> I'm having a difficult time parsing a delimited string.
>
> e.g.
>
> 100657641~GBP~ACTIVE~0~1~~true~5.0~1247065352508~:
> 3818854~0~24104.08~4.5~~22.1~false|4.4~241.67~L~1~4.3~936.0~L~2~4.2~210.54~L~3~|4.5~19.16~B~1~4.6~214.27~B~2~4.7~802.13~B~3~:
> 3991404~1~19974.18~4.7~~21.7~false|4.6~133.01~L~1~4.5~124.83~L~2~4.4~319.33~L~3~|4.7~86.61~B~1~4.8~247.9~B~2~4.9~142.0~B~3~:
> 4031423~2~15503.56~6.6~~15.1~false|6.6~53.21~L~1~6.4~19.23~L~2~6.2~53.28~L~3~|6.8~41.23~B~1~7.0~145.04~B~2~7.2~37.23~B~3~
>
> That is just a selection of the full string - and I've broken it up
> for this email.  It's delimited by : and then by ~ and finally, in
> some cases, | (a pipe).
>
> If the string is called m, I thought I could create a list with
> m.split(":").  I would like to then first of all find in this list the
> entry beginning with e.g. 3991404.

A couple of splits and a search will do it:

In [1]: data = """100657641~GBP~ACTIVE~0~1~~true~5.0~1247065352508~:
   ...: 
3818854~0~24104.08~4.5~~22.1~false|4.4~241.67~L~1~4.3~936.0~L~2~4.2~210.54~L~3~|4.5~19.16~B~1~4.6~214.27~B~2~4.7~802.1
3~B~3~:
   ...:
3991404~1~19974.18~4.7~~21.7~false|4.6~133.01~L~1~4.5~124.83~L~2~4.4~319.33~L~3~|4.7~86.61~B~1~4.8~247.9~B~2~4.9~1
42.0~B~3~:
   ...:
4031423~2~15503.56~6.6~~15.1~false|6.6~53.21~L~1~6.4~19.23~L~2~6.2~53.28~L~3~|6.8~41.23~B~1~7.0~145.04~B~2~7.2
~37.23~B~3~"""

In [6]: items = [ item.strip().split('~') for item in data.split(':') ]

The strip() is only needed because when I pasted your string the
interpreter introduced white space.

In [7]: for item in items:
   ...: print item[0]

100657641
3818854
3991404
4031423

In [9]: for item in items:
   ...: if item[0] == '3991404':
   ...: print item[3]

4.7

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


Re: [Tutor] error message

2009-07-08 Thread Emile van Sebille

On 7/8/2009 9:13 AM Steven Buck said...
I'm running a for loop which returns an error message after the third 
iteration (see out[4] at the bottom as evidence).  I don't understand 
the error message.  Although I'll continue to do my own digging to 
debug, I thought I'd give you all a shot.  Thanks, -steve
 



age[(i)] = psid.psid[i][20]

Here you're getting the 20th field from the 4th record.  So, assuming 
the tools you're using are OK...



--> 150 d = unpack(self._header['byteorder']+fmt, byt)[0]



error: unpack requires a string argument of length 1


... you get an unpack error.  So my money's on a source data problem.

you might try...

for ii in range(40):
print psid.psid[3][ii]

...and see what you get.  It's likely a bad record of some sort.  You 
might need to allow for those...



HTH,

Emile


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


Re: [Tutor] Quick question regarding Parsing a Delimited string

2009-07-08 Thread Kent Johnson
On Wed, Jul 8, 2009 at 1:22 PM, Rich Lovely wrote:

> If you really want to speed up the search, you could turn the list of lists
> into a dict, using the first value in each sublist as a key:
>
> dct = dict((i[0], i[1:]) for i in lst)
>
> Then you can access it using the normal dictionary interface.
> dct["3991404"][3]

I'm suspicious of this claim if there is only one lookup needed. You
iterate the whole list and incur the overhead of constructing a dict.
If there will be multiple lookups it may well be a win but as always
there is no substitute for measurement if you want to know what is
faster.

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


Re: [Tutor] Quick question regarding Parsing a Delimited string

2009-07-08 Thread Garry Bettle
On Wed, Jul 8, 2009 at 21:37, Kent Johnson wrote:
> On Wed, Jul 8, 2009 at 1:22 PM, Rich Lovely wrote:
>
>> If you really want to speed up the search, you could turn the list of lists
>> into a dict, using the first value in each sublist as a key:
>>
>> dct = dict((i[0], i[1:]) for i in lst)
>>
>> Then you can access it using the normal dictionary interface.
>> dct["3991404"][3]
>
> I'm suspicious of this claim if there is only one lookup needed. You
> iterate the whole list and incur the overhead of constructing a dict.
> If there will be multiple lookups it may well be a win but as always
> there is no substitute for measurement if you want to know what is
> faster.
>
> Kent
>

Hi Kent,

No, I think the dict will be fine:  I have to find every one that is
in my original list.

Many thanks to both you and Rich for all the help.  I'll let you know
how I get on.

Cheers,

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


Re: [Tutor] error message

2009-07-08 Thread bob gailer




Steven Buck wrote:

  I'm running a for loop which returns an error message after the
third iteration (see out[4] at the bottom as evidence).  I don't
understand the error message.  Although I'll continue to do my own
digging to debug, I thought I'd give you all a shot.  Thanks, -steve
   
  Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32
bit (Intel)]
Type "copyright", "credits" or "license" for more information.
  IPython 0.9.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help  -> Python's own help system.
object?   -> Details about 'object'. ?object also works, ?? prints
more.
  In [1]: import psid
  In [2]: age = {}
  In [3]: for i in range(len(psid.psid)):
   ...: age[(i)] = psid.psid[i][20]
   ...:
   ...:
---
error Traceback (most recent call
last)
  C:\Documents and Settings\Steve\ in
()
  C:\Python26\lib\site-packages\StataTools.pyc in
__getitem__(self, k)
 85 if self._file.tell() != loc:
 86 self._file.seek(loc)
---> 87 return self._next()
 88
 89 ### PyDTA private methods
  
C:\Python26\lib\site-packages\StataTools.pyc in _next(self)
    167 else:
    168 data[i] = self._unpack(typlist[i],
self._file.read(s
elf._col_size(i)))
    169 return data
    170 else:
--> 171 return map(lambda i: self._unpack(typlist[i],
self._file.rea
d(self._col_size(i))), range(self._header['nvar']))
  C:\Python26\lib\site-packages\StataTools.pyc in (i)
    167 else:
    168 data[i] = self._unpack(typlist[i],
self._file.read(s
elf._col_size(i)))
    169 return data
    170 else:
--> 171 return map(lambda i: self._unpack(typlist[i],
self._file.rea
d(self._col_size(i))), range(self._header['nvar']))
  C:\Python26\lib\site-packages\StataTools.pyc in _unpack(self,
fmt, byt)
    148
    149 def _unpack(self, fmt, byt):
  


Add here (temporarily) print  self._header['byteorder'], fmt, byt
make sure it is indented the same as 150.
Let's examine the 4th printed line.


  --> 150 d = unpack(self._header['byteorder']+fmt,
byt)[0]
    151 if fmt[-1] in self.MISSING_VALUES:
    152 nmin, nmax = self.MISSING_VALUES[fmt[-1]]
  error: unpack requires a string argument of length 1
  In [4]: age
Out[4]: {0: 22, 1: 51, 2: 42}
  In [5]:
  

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



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


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


Re: [Tutor] error message

2009-07-08 Thread Steven Buck
As Bob prescribed, I added (and made sure to indent):

print self._header['byteorder'], fmt, byt

The fourth printed line appears to be the same:
Out[4]: {0: 22, 1: 51, 2: 42}

This is consistent with what I observe as the first three age observations
in the Stata data editor.

I include the rest of the error message I received (& could capture) below.
Any more thoughts?
Thanks
Steve

< b ▬
< b §
< b ☺
< b ☺
< b ☺
< b ☻
< b ☺
< f  PCF
< b ♣
< f ∞Qê@
< b ☺
< f   `A
< b ☺
< b ♣
< f
< f
< b
< b
< b ♣
< h ╥
< f   ßC
< b e
< b ♣
< b
< b
< b
< b ☺
< b ♥
< b ♥
< b ☺
< h ñ
< h
< f 5î─D
< b ☺
< b
< b
< b
< b
< b
< b ☺
< b ☺
< h Σ☺
< b ☺
< b ☺
< f   ÉB
< f ÜÖôB
< f ÜÖêB
< f   âB
< f ═╠ƒB
< f ÜÖàB
< f ÜÖúB
< f ffzB
< f ═╠ùB
< f fféB
< f ffrB
< f 33æB
< f ∞Q8?
< f ü↓ⁿ@
< f «1¿╛
< f b♥2A
< f �...@a
< f ♠·OA
< f ╟▌QA
< f   Ç?
< h ⌠←
< b
< h ║
< h <☻
< f  áîF
< f
< h (♣
< f   èE
< h
< h ╝
< h
< f  α½F
< f
< f  α½F
< f   ╥E
< f  hαF
< f   }E
< b "
< b ☺
< b ☻
< b 3
< b 1
< b ☺
< b ☻
< b ☺
< b ☺
< b ☺
< f  α½F
< b e
< f Å┬1A
< b
< f   ,B
< b ♣
< b ♣
< f
< f
< b
< b ☺
< b ♣
< h
< f
< b e
< b ☺
< b ☺
< b
< b
< b ☻
< b ☺
< b ☺
< b ☻
< h ç
< h
< f 8↑sE
< b
< b ☺
< b
< b
< b ☺
< b
< b
< b
< h )
< b ☺
< b
< f   ÉB
< f ÜÖôB
< f ÜÖêB
< f   âB
< f ═╠ƒB
< f ÜÖàB
< f ÜÖúB
< f ffzB
< f ═╠ùB
< f fféB
< f ffrB
< f 33æB
< f ∞Q8?
< f ≥Ä♂A
< f «1¿╛
< f ░₧CA
< f _iXA
< f ↑├`A
< f ♫»iA
< f   Ç@
< h àD
< b ☺
< h ║
< h Ñ♥
< f
< f  Ç╨D
< h
< f   ☻E
< h
< h ╚♠
< h
< f  @£E
< f
< f  @£E
< f
< f  @£E
< f
< b
< b ☻
< b ☻
< b *
< b )
< b ☺
< b
< b ☺
< b ☺
< b ☺
< f  @£E
< b ☺
< f ∞Q8@
< b
< f   Ç?
< b ☺
< b ♣
< f
< f
< b
< b
< b ♣
< h
< f
< b e
< b ♣
< b
< b
< b
< b ☻
< b ☻
< b ☻
< b ♥
< h É
< h
< f ^ë↑D
< b
< b
< b ☺
< b
< b
< b ☺
< b
< b
< h Σ♠
< b ☺
< b
< f   ÉB
< f ÜÖôB
< f ÜÖêB
< f   âB
< f ═╠ƒB
< f ÜÖàB
< f ÜÖúB
< f ffzB
< f ═╠ùB
< f fféB
< f ffrB
< f 33æB
< f ∞Q8?
< f ■■■@
< f «1¿╛
< f ä▐3A
< f :─CA
< f ¡♫RA
< f bVUA
< f   @@
< h ▐►
< b
< h ║
< h ►►
< f
< f   aD
< h X☻
< f  Ç"E
< h
< h ÷
< h ≡
< f  ╝TF
< f   HD
< f  αvF
< f
< f  αvF
< f   »D
< b ↑
< b ♣
< b ♣
< b
---
error Traceback (most recent call last)
C:\Documents and Settings\Steve\ in ()
C:\Python26\lib\site-packages\StataTools.py in __getitem__(self, k)
 85 if self._file.tell() != loc:
 86 self._file.seek(loc)
---> 87 return self._next()
 88
 89 ### PyDTA private methods

C:\Python26\lib\site-packages\StataTools.py in _next(self)
168 else:
169 data[i] = self._unpack(typlist[i],
self._file.read(s
elf._col_size(i)))
170 return data
171 else:
--> 172 return map(lambda i: self._unpack(typlist[i],
self._file.rea
d(self._col_size(i))), range(self._header['nvar']))
C:\Python26\lib\site-packages\StataTools.py in (i)
168 else:
169 data[i] = self._unpack(typlist[i],
self._file.read(s
elf._col_size(i)))
170 return data
171 else:
--> 172 return map(lambda i: self._unpack(typlist[i],
self._file.rea
d(self._col_size(i))), range(self._header['nvar']))
C:\Python26\lib\site-packages\StataTools.py in _unpack(self, fmt, byt)
149 def _unpack(self, fmt, byt):
150 print self._header['byteorder'], fmt, byt
--> 151 d = unpack(self._header['byteorder']+fmt, byt)[0]
152 if fmt[-1] in self.MISSING_VALUES:
153 nmin, nmax = self.MISSING_VALUES[fmt[-1]]
error: unpack requires a string argument of length 1
In [4]: age
Out[4]: {0: 22, 1: 51, 2: 42}
In [5]:


On Wed, Jul 8, 2009 at 1:12 PM, bob gailer  wrote:

>   Steven Buck wrote:
>
> I'm running a for loop which returns an error message after the third
> iteration (see out[4] at the bottom as evidence).  I don't understand the
> error message.  Although I'll continue to do my own digging to debug, I
> thought I'd give you all a shot.  Thanks, -steve
>
> Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit
> (Intel)]
> Type "copyright", "credits" or "license" for more information.
> IPython 0.9.1 -- An enhanced Interactive Python.
> ? -> Introduction and overview of IPython's features.
> %quickref -> Quick reference.
> help  -> Python's own help system.
> object?   -> Details about 'object'. ?object also works, ?? prints more.
> In [1]: import psid
> In [2]: age = {}
> In [3]: for i in range(len(psid.psid)):
>...: age[(i)] = psid.psid[i][20]
>...:
>...:
> ---
> error Traceback (most recent call last)
> C:\Documents and Settings\Steve\ in ()
> C:\Python26\lib\site-packages\StataTools.pyc in __getitem__(self, k)
>  85 if self._file.tell() != loc:
>  86 self._file.seek(loc)
> ---> 87 return self._next()
>  8

[Tutor] thesaurus

2009-07-08 Thread Pete Froslie
okay.. I'm getting the hang of python a little more. I'd like to try
something a bit more complicated (for me). I would like to convert each word
in a series of paragraphs to its first matching synonym in a thesaurus. I'm
a bit stuck as how to start.. I think I understand how to split and parse
the original paragraphs, but the thesaurus is throwing me. I'm thinking
maybe find a CSV thesaurus -or- a thesaurus online with an API.. I'm
wondering if anyone has done something similar that may point me in the
correct direction?


thanks,

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


Re: [Tutor] Python Tutorials: How to create useful programs after learning the syntax?

2009-07-08 Thread wesley chun
On Sun, Jul 5, 2009 at 11:48 PM, Luis Galvan wrote:
> Hello all, this is my first time using a mailing list, so I'm not sure if
> I'm doing this right!  Anyway, I have a wee bit of a problem.  I've recently
> completed watching a Youtube video series on Python 2.6 by thenewboston
> which helped me a TON with learning Python's syntax and how to use some of
> the various builtin modules.  I am very thankful for his tutorials, but the
> only thing that I need is something to help me really grasp onto the world
> of programming. (I'm new to programming)  What I'm looking for is a tutorial
> series that walks you through the steps of writing a useful program in
> Python.


luis,

no sales pitch here (or at least none intended), but if you ever come
across a copy of "Core Python Programming," i've put lots of exercises
at the end of every chapter. not all of them are full-scale
applications, but it is good practice writing snippets of code that at
some point may be plugged *into* an application at some point.

best regards, and welcome to Python!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
"Python Fundamentals", Prentice Hall, (c)2009
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Tutorials: How to create useful programs after learning the syntax?

2009-07-08 Thread python
> but if you ever come across a copy of "Core Python Programming," i've put 
> lots of exercises at the end of every chapter.

+1 from a reader/customer (vs. the author)

"Core Python Programming" is an excellent resource for learning Python.
I enjoyed the exercises - they force you to master the content vs.
thinking you know what's going on via a fast skim of the content.

Highly recommended!

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


Re: [Tutor] Python Tutorials: How to create useful programs after learning the syntax?

2009-07-08 Thread Emile van Sebille

but if you ever come across a copy of "Core Python Programming," i've put lots 
of exercises at the end of every chapter.


+1 from a reader/customer (vs. the author)


+1 from a reviewer (vs. a reader/customer (vs. the author))

:)

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


Re: [Tutor] thesaurus

2009-07-08 Thread Robert Berman
http://pywordnet.sourceforge.net/

This will get you started. This is a tad easier to play with than its
newer implementation. Read and experiment. it may meet most of your
needs in this arena.

Good Luck,

Robert



On Wed, 2009-07-08 at 18:28 -0400, Pete Froslie wrote:
> okay.. I'm getting the hang of python a little more. I'd like to try
> something a bit more complicated (for me). I would like to convert
> each word in a series of paragraphs to its first matching synonym in a
> thesaurus. I'm a bit stuck as how to start.. I think I understand how
> to split and parse the original paragraphs, but the thesaurus is
> throwing me. I'm thinking maybe find a CSV thesaurus -or- a thesaurus
> online with an API.. I'm wondering if anyone has done something
> similar that may point me in the correct direction?
> 
> 
> thanks,
> 
> -- 
> Pete F
> ___
> 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] Python Tutorials: How to create useful programs after learning the syntax?

2009-07-08 Thread Robert Berman
While it is not a sales pitch, the book is excellent. It and the Python
Cookbook sit on top of my desk. Both are fantastic and pragmatic
reference sources.

Robert



On Wed, 2009-07-08 at 16:10 -0700, wesley chun wrote:
> On Sun, Jul 5, 2009 at 11:48 PM, Luis Galvan wrote:
> > Hello all, this is my first time using a mailing list, so I'm not sure if
> > I'm doing this right!  Anyway, I have a wee bit of a problem.  I've recently
> > completed watching a Youtube video series on Python 2.6 by thenewboston
> > which helped me a TON with learning Python's syntax and how to use some of
> > the various builtin modules.  I am very thankful for his tutorials, but the
> > only thing that I need is something to help me really grasp onto the world
> > of programming. (I'm new to programming)  What I'm looking for is a tutorial
> > series that walks you through the steps of writing a useful program in
> > Python.
> 
> 
> luis,
> 
> no sales pitch here (or at least none intended), but if you ever come
> across a copy of "Core Python Programming," i've put lots of exercises
> at the end of every chapter. not all of them are full-scale
> applications, but it is good practice writing snippets of code that at
> some point may be plugged *into* an application at some point.
> 
> best regards, and welcome to Python!
> -- wesley
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> "Core Python Programming", Prentice Hall, (c)2007,2001
> "Python Fundamentals", Prentice Hall, (c)2009
> http://corepython.com
> 
> wesley.j.chun :: wescpy-at-gmail.com
> python training and technical consulting
> cyberweb.consulting : silicon valley, ca
> http://cyberwebconsulting.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] using datetime and calculating hourly average

2009-07-08 Thread Alan Gauld


"John [H2O]"  wrote 


--> 196 ind = np.where( (t1 < Y[:,0] < t2) ) #same result

TypeError: can't compare datetime.datetime to numpy.ndarray


Have you checked what you are comparing?
Try printing Y[:,0]
It looks like an invalid test and no amolunt of parenthesising 
or 'and'ing will make it work.



--> 196 ind = np.where( (Y[:,0]>t1) and (Y[:,0]

Looks like the Y[:,0] value is not compatible with the time t1 or t2.

What does 

print Y[:,0] 


produce?


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

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


[Tutor] Fwd: thesaurus

2009-07-08 Thread Pete Froslie
-- Forwarded message --
From: Pete Froslie 
Date: Wed, Jul 8, 2009 at 8:53 PM
Subject: Re: [Tutor] thesaurus
To: Robert Berman 


Thanks Robert,

I will try this out.. at the moment I'm playing with an API from '
http://words.bighugelabs.com/'. It works and pulls the synonyms into python.
It cost money if you want to process more than 10,000 in a day though.

I do have another pretty noob question that I'm figuring out -- once I have
a list of synonyms returned, is there a simple way to replace the words I
looked up inside of the 'txt' file?

For instance, I open and read the 'txt' file, grab the first word, search it
with the thesaurus, get the result, write the result back to the file, and
then grab the next word to repeat the process. It seems like there is
probably a quick shortcut for this..

thanks so much




On Wed, Jul 8, 2009 at 8:25 PM, Robert Berman  wrote:

> http://pywordnet.sourceforge.net/
>
> This will get you started. This is a tad easier to play with than its
> newer implementation. Read and experiment. it may meet most of your
> needs in this arena.
>
> Good Luck,
>
> Robert
>
>
>
> On Wed, 2009-07-08 at 18:28 -0400, Pete Froslie wrote:
> > okay.. I'm getting the hang of python a little more. I'd like to try
> > something a bit more complicated (for me). I would like to convert
> > each word in a series of paragraphs to its first matching synonym in a
> > thesaurus. I'm a bit stuck as how to start.. I think I understand how
> > to split and parse the original paragraphs, but the thesaurus is
> > throwing me. I'm thinking maybe find a CSV thesaurus -or- a thesaurus
> > online with an API.. I'm wondering if anyone has done something
> > similar that may point me in the correct direction?
> >
> >
> > thanks,
> >
> > --
> > Pete F
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Pete Froslie
617.314.0957
http://www.froslie.net




-- 
Pete Froslie
617.314.0957
http://www.froslie.net
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: thesaurus

2009-07-08 Thread Rich Lovely
2009/7/9 Pete Froslie :
>
>
> -- Forwarded message --
> From: Pete Froslie 
> Date: Wed, Jul 8, 2009 at 8:53 PM
> Subject: Re: [Tutor] thesaurus
> To: Robert Berman 
>
>
> Thanks Robert,
>
> I will try this out.. at the moment I'm playing with an API from
> 'http://words.bighugelabs.com/'. It works and pulls the synonyms into
> python. It cost money if you want to process more than 10,000 in a day
> though.
>
> I do have another pretty noob question that I'm figuring out -- once I have
> a list of synonyms returned, is there a simple way to replace the words I
> looked up inside of the 'txt' file?
>
> For instance, I open and read the 'txt' file, grab the first word, search it
> with the thesaurus, get the result, write the result back to the file, and
> then grab the next word to repeat the process. It seems like there is
> probably a quick shortcut for this..
>
> thanks so much
>
>
>

Assuming lookup() handles punctuation and capitalisation...

import sys

if sys.version_info < (2,5):
print "This script needs a more recent version of python"
sys.exit(1)
elif sys.version_info < (2,6):
from __future__ import with_statement

buff = []
with open("path_to_input_file", "r") as fin:
for line in fin:
buff.append(" ".join(lookup(word) for word in line.split()))

with open("path_to_output_file", "w") as fout:
fout.write("\n".join(buff))

This is also a good intro to the with statement, which cleans
everything up for you.  Unfortunatly, it was only introduced in 2.5 as
a __future__ feature, and 2.6 as a final feature.  If you've got a
version prior to that, you'll need to rework it a little, or upgrade.

But I think this gives the general idea.  I don't think there's any
more concise way of doing it than that in python.

You also might want to use print instead of writing straight to a
file, and use the terminal's stream redirection to put the output into
a file.

-- 
Richard "Roadie Rich" Lovely, part of the JNP|UK Famile
www.theJNP.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: thesaurus

2009-07-08 Thread Pete Froslie
Great Richard, thanks..

I'm getting an error as follows:

from __future__ import with_statement
SyntaxError: from __future__ imports must occur at the beginning of the file

I don't think this is the issue in need of rework and have tried a few quick
reworks.. I'll read up a bit on 'with'

cheers


On Wed, Jul 8, 2009 at 9:41 PM, Rich Lovely wrote:

> 2009/7/9 Pete Froslie :
> >
> >
> > -- Forwarded message --
> > From: Pete Froslie 
> > Date: Wed, Jul 8, 2009 at 8:53 PM
> > Subject: Re: [Tutor] thesaurus
> > To: Robert Berman 
> >
> >
> > Thanks Robert,
> >
> > I will try this out.. at the moment I'm playing with an API from
> > 'http://words.bighugelabs.com/'. It works and pulls the synonyms into
> > python. It cost money if you want to process more than 10,000 in a day
> > though.
> >
> > I do have another pretty noob question that I'm figuring out -- once I
> have
> > a list of synonyms returned, is there a simple way to replace the words I
> > looked up inside of the 'txt' file?
> >
> > For instance, I open and read the 'txt' file, grab the first word, search
> it
> > with the thesaurus, get the result, write the result back to the file,
> and
> > then grab the next word to repeat the process. It seems like there is
> > probably a quick shortcut for this..
> >
> > thanks so much
> >
> >
> >
>
> Assuming lookup() handles punctuation and capitalisation...
>
> import sys
>
> if sys.version_info < (2,5):
>print "This script needs a more recent version of python"
>sys.exit(1)
> elif sys.version_info < (2,6):
>from __future__ import with_statement
>
> buff = []
> with open("path_to_input_file", "r") as fin:
>for line in fin:
>buff.append(" ".join(lookup(word) for word in line.split()))
>
> with open("path_to_output_file", "w") as fout:
>fout.write("\n".join(buff))
>
> This is also a good intro to the with statement, which cleans
> everything up for you.  Unfortunatly, it was only introduced in 2.5 as
> a __future__ feature, and 2.6 as a final feature.  If you've got a
> version prior to that, you'll need to rework it a little, or upgrade.
>
> But I think this gives the general idea.  I don't think there's any
> more concise way of doing it than that in python.
>
> You also might want to use print instead of writing straight to a
> file, and use the terminal's stream redirection to put the output into
> a file.
>
> --
> Richard "Roadie Rich" Lovely, part of the JNP|UK Famile
> www.theJNP.com
>



-- 
Pete Froslie
617.314.0957
http://www.froslie.net
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: thesaurus

2009-07-08 Thread Rich Lovely
2009/7/9 Pete Froslie :
> Great Richard, thanks..
>
> I'm getting an error as follows:
>
> from __future__ import with_statement
> SyntaxError: from __future__ imports must occur at the beginning of the file
>
> I don't think this is the issue in need of rework and have tried a few quick
> reworks.. I'll read up a bit on 'with'
>
> cheers
>
>

(Appologies for my inital, incomplete email...)
Oops... forgot it wasn't a standard import...

Just move it to the first line of the program, and delete the relevant
elif branch.

It won't hurt code on more recent versions.

from __future__ import with_statement
import sys

buff = []
with open("path_to_input_file", "r") as fin:
   for line in fin:
   buff.append(" ".join(lookup(word) for word in line.split()))

with open("path_to_output_file", "w") as fout:
   fout.write("\n".join(buff))

-- 
Richard "Roadie Rich" Lovely, part of the JNP|UK Famile
www.theJNP.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: thesaurus

2009-07-08 Thread Pete Froslie
No problem, thanks for taking the time.

I'm actually trying to resolve this error now:

   buff.append(" ".join(lookup(Word) for Word in line.split()))
NameError: global name 'lookup' is not defined

..also assume I need to change 'Word' to something that checks the next word
in the text file and then replaces it with the one that is looked up..
working on that now.

Pete F

On Wed, Jul 8, 2009 at 10:10 PM, Rich Lovely wrote:

> 2009/7/9 Pete Froslie :
> > Great Richard, thanks..
> >
> > I'm getting an error as follows:
> >
> > from __future__ import with_statement
> > SyntaxError: from __future__ imports must occur at the beginning of the
> file
> >
> > I don't think this is the issue in need of rework and have tried a few
> quick
> > reworks.. I'll read up a bit on 'with'
> >
> > cheers
> >
> >
>
> (Appologies for my inital, incomplete email...)
> Oops... forgot it wasn't a standard import...
>
> Just move it to the first line of the program, and delete the relevant
> elif branch.
>
> It won't hurt code on more recent versions.
>
> from __future__ import with_statement
> import sys
>
> buff = []
> with open("path_to_input_file", "r") as fin:
>   for line in fin:
>   buff.append(" ".join(lookup(word) for word in line.split()))
>
> with open("path_to_output_file", "w") as fout:
>   fout.write("\n".join(buff))
>
> --
> Richard "Roadie Rich" Lovely, part of the JNP|UK Famile
> www.theJNP.com
>



-- 
Pete Froslie
617.314.0957
http://www.froslie.net
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: thesaurus

2009-07-08 Thread Rich Lovely
2009/7/9 Pete Froslie :
> No problem, thanks for taking the time.
>
> I'm actually trying to resolve this error now:
>
>    buff.append(" ".join(lookup(Word) for Word in line.split()))
> NameError: global name 'lookup' is not defined
>
> ..also assume I need to change 'Word' to something that checks the next word
> in the text file and then replaces it with the one that is looked up..
> working on that now.
>
> Pete F

lookup() is the function that looks up the word in the thesaurus.  I
left implementing that as an exercise for you, as I don't know the
format of the reference you're using.
-- 
Richard "Roadie Rich" Lovely, part of the JNP|UK Famile
www.theJNP.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: thesaurus

2009-07-08 Thread Pete Froslie
I see.. that makes sense. Kind of new with python -- sorry for that.

after printing using this:

print urllib.urlopen('
http://words.bighugelabs.com/api/2/e413f24801aa30b8d441ca43a64317be/moving/').read(
)

I'm getting a format like this returned:

adjective|sim|streaming
adjective|sim|swirling
adjective|sim|tossing
adjective|sim|touching
adjective|sim|touring
adjective|sim|traveling
adjective|sim|tumbling

I assume I need to clean this up by reading past  'Adjective|sim|' to
'streaming' and then returning it from lookup()..
this will be happening in the following:

urllib.urlopen('
http://words.bighugelabs.com/api/2/e413f24801aa30b8d441ca43a64317be/moving/').read(SOMETHINGHERE)



On Wed, Jul 8, 2009 at 10:29 PM, Rich Lovely wrote:

> 2009/7/9 Pete Froslie :
> > No problem, thanks for taking the time.
> >
> > I'm actually trying to resolve this error now:
> >
> >buff.append(" ".join(lookup(Word) for Word in line.split()))
> > NameError: global name 'lookup' is not defined
> >
> > ..also assume I need to change 'Word' to something that checks the next
> word
> > in the text file and then replaces it with the one that is looked up..
> > working on that now.
> >
> > Pete F
>
> lookup() is the function that looks up the word in the thesaurus.  I
> left implementing that as an exercise for you, as I don't know the
> format of the reference you're using.
> --
> Richard "Roadie Rich" Lovely, part of the JNP|UK Famile
> www.theJNP.com
>



-- 
Pete Froslie
617.314.0957
http://www.froslie.net
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: thesaurus

2009-07-08 Thread Pete Froslie
oops.. I just realized I attached the wrong example for the API-- it was off
by number, this one works:

print urllib.urlopen('
http://words.bighugelabs.com/api/2/e413f24701aa30b8d441ca43a64317be/moving/').read(
)

The example makes sense to me and I can see how it is difficult to figure
out a natural language parser.. as it turns out, I don't mind it for this
project--gibberish is fine. Though I am now pretty curious about NL
parsers-- thanks for the example..

I will look at using the split method of strings..

On Wed, Jul 8, 2009 at 11:12 PM, Rich Lovely wrote:

> 2009/7/9 Pete Froslie :
> > I see.. that makes sense. Kind of new with python -- sorry for that.
> >
> > after printing using this:
> >
> > print
> > urllib.urlopen('
> http://words.bighugelabs.com/api/2/e413f24801aa30b8d441ca43a64317be/moving/').read(
> )
> >
> > I'm getting a format like this returned:
> >
> > adjective|sim|streaming
> > adjective|sim|swirling
> > adjective|sim|tossing
> > adjective|sim|touching
> > adjective|sim|touring
> > adjective|sim|traveling
> > adjective|sim|tumbling
> >
> > I assume I need to clean this up by reading past  'Adjective|sim|' to
> > 'streaming' and then returning it from lookup()..
> > this will be happening in the following:
> >
> > urllib.urlopen('
> http://words.bighugelabs.com/api/2/e413f24801aa30b8d441ca43a64317be/moving/').read(SOMETHING
> > HERE)
> >
> >
> >
> I don't think there is any easy way of doing that.
>
> You would be better off using the split method of the strings, and
> ignoring the first parts for now.
>
> Have you considered what happens with the word set in the following
> sentance, about testing TV receivers:
>
> We've set the code number of each set to a reasonable value for this
> set of experiments.
>
> I can't get the api to work for me, but the way you're doing it at the
> moment, you'd end up with something like
>
> We've fixed the code number of each fixed to a reasonable value for
> this fixed of experiments.
>
> A contrived example, I know, but it makes the point.
>
> Unless, of course, this sort of gibberish is what you're after.
>
> Natural language parsers are one of the hardest things to create.
> Just look up the word "set" in a dictionary to see why.  Even if you
> did work out that the second "set" was a noun, is it "a radio or
> television receiver" or "a group or collection of things that belong
> together, resemble one another, or are usually found together"
>
> --
> Richard "Roadie Rich" Lovely, part of the JNP|UK Famile
> www.theJNP.com
>



-- 
Pete Froslie
617.314.0957
http://www.froslie.net
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: thesaurus

2009-07-08 Thread Rich Lovely
2009/7/9 Pete Froslie :
> I see.. that makes sense. Kind of new with python -- sorry for that.
>
> after printing using this:
>
> print
> urllib.urlopen('http://words.bighugelabs.com/api/2/e413f24801aa30b8d441ca43a64317be/moving/').read()
>
> I'm getting a format like this returned:
>
> adjective|sim|streaming
> adjective|sim|swirling
> adjective|sim|tossing
> adjective|sim|touching
> adjective|sim|touring
> adjective|sim|traveling
> adjective|sim|tumbling
>
> I assume I need to clean this up by reading past  'Adjective|sim|' to
> 'streaming' and then returning it from lookup()..
> this will be happening in the following:
>
> urllib.urlopen('http://words.bighugelabs.com/api/2/e413f24801aa30b8d441ca43a64317be/moving/').read(SOMETHING
> HERE)
>
>
>
I don't think there is any easy way of doing that.

You would be better off using the split method of the strings, and
ignoring the first parts for now.

Have you considered what happens with the word set in the following
sentance, about testing TV receivers:

We've set the code number of each set to a reasonable value for this
set of experiments.

I can't get the api to work for me, but the way you're doing it at the
moment, you'd end up with something like

We've fixed the code number of each fixed to a reasonable value for
this fixed of experiments.

A contrived example, I know, but it makes the point.

Unless, of course, this sort of gibberish is what you're after.

Natural language parsers are one of the hardest things to create.
Just look up the word "set" in a dictionary to see why.  Even if you
did work out that the second "set" was a noun, is it "a radio or
television receiver" or "a group or collection of things that belong
together, resemble one another, or are usually found together"

-- 
Richard "Roadie Rich" Lovely, part of the JNP|UK Famile
www.theJNP.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor