Re: [Tutor] MONEY MATTERS

2007-03-22 Thread wesley chun
> ok, SHOULD THIS BE A THREAD OR A SEPERATE LIST?
>
> Many of ius are independants, and write code for the love of it- or to
> promote and sell independantly. So possibly a thread discussing ways to
>   turn useful code into moiney is a useful idea. If the wish of the list
> is a thread here, we can do that, or we can start a seperate list for
> it. What are the wishes of this list?


i don't think this is the right forum for such a thread.  the main
Python thread may be a better place, but i'd better *DUCK* before
someone from other there throws anything at me.  :-)  this list is
really meant for those who are either new to programming or new to
Python, or both, to ask questions and get answers.

perhaps an even *better* place would be to place this on your blog,
and let respondents take the thread in any direction, yet have it be
archived for all to read.

cheers,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
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] Making table

2007-03-22 Thread Alan Gauld

"Kent Johnson" <[EMAIL PROTECTED]> wrote in message

>> One final tip is to put the format string in a variable then use 
>> that
>> in printing/writing the output ...
>> This has the advantage that you can build the format string
>> dynamically by examining the data first - eg the maximum
>> length of an entry.

> You don't need to build the format string dynamically to get control 
> of
> the maximum width. A neat trick is that if you use '*' for the 
> format
> width, the width will be read from the parameter list:

Good point, I usually forget that one...

However predefined format strings have other advantages too
- consistency for one thing. You can write output in multiple
places and be sure the format is consistent throughout.

Alan G. 


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


Re: [Tutor] MONEY MATTERS

2007-03-22 Thread Steve Oldner
My 2 cents worth is to set up something separate, it'll just keep the
principles and ideas clearer.  While I have my own ideas about the
"million dollar application", I would like a forum where I can just
listen and learn any type of ideas without having a worry that someone
will 'steal' my idea and beat me to the market.

I work for a state government supporting a SAP HR application, so
anything I learn from this list is not directly applicable to my job.
However, the ideas and logic to solve various PYTHON solutions is a big
benefit in expanding my search for alternative solutions.

And one day, I will have free time to work on my "million dollar app."
(LOL!)

Thanks,

Steve Oldner  

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Kirk Bailey
Sent: Wednesday, March 21, 2007 10:14 PM
To: tutor@python.org
Subject: [Tutor] MONEY MATTERS

ok, SHOULD THIS BE A THREAD OR A SEPERATE LIST?

Many of ius are independants, and write code for the love of it- or to
promote and sell independantly. So possibly a thread discussing ways to
  turn useful code into moiney is a useful idea. If the wish of the list
is a thread here, we can do that, or we can start a seperate list for
it. What are the wishes of this list?

-- 
Salute!
-Kirk Bailey
   Think
  +-+
  | BOX |
  +-+
   knihT

Fnord.
___
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] Should I use python for parsing text?

2007-03-22 Thread Kent Johnson
Jay Mutter III wrote:
> Kent;
> 
> Thanks for the reply on tutor-python.
> 
> My data file which is just a .txt file created under WinXP by an OCR 
> program contains lines like:
> 
> A.-C. Manufacturing Company. (See Sebastian, A. A.,
> and Capes, assignors.)
> A. G. A. Railway Light & Signal Co. (See Meden, Elof
> H„ assignor.)
> A-N Company, The. (See Alexander and Nasb, as-
> signors.;
> AN Company, The. (See Nash, It. J., and Alexander, as-
> signors.)
> 
> I use an intel imac running OS x10.4.9 and when I used python to append 
> one file to another I got a file that opened in OS X's
> TexEdit program with characters that looked liked Japanese/Chinese 
> characters.
> 
> When i pasted them into my mail client (OS X's mail) they were then just 
> a sequence of question marks so I am not sure what happened.
> 
> Any thoughts???

For some reason, after you run the Python program, TexEdit thinks the 
file is not ascii data; it seems to think it is utf-8 or a Chinese 
encoding. Your original email was utf-8 which points in that direction 
but is not conclusive.

If you zip up and send me the original file and the cleandata.txt file 
*exactly as it is produced* by the Python program - not edited in any 
way - I will take a look and see if I can guess what is going on.
> 
> And i tried  using the following on the above data:
> 
> in_filename = raw_input('What is the COMPLETE name of the file you want 
> to open:')
> in_file = open(in_filename, 'r')

It wouldn't hurt to use universal newlines here since you are working 
cross-platform:
   open(in_filename, 'Ur')

> text = in_file.readlines()
> num_lines = text.count('\n')

Here 'text' is a list of lines, so text.count('\n') is counting the 
number of blank lines (lines containing only a newline) in your file. 
You should use
   num_lines = len(text)

> print 'There are', num_lines, 'lines in the file', in_filename
> 
> output = open("cleandata.txt","a")# file for writing data to after 
> stripping newline character

I agree with Luke, use 'w' for now to make sure the file has only the 
output of this program. Maybe something already in the file is making it 
look like utf-8...

> 
> # read file, copying each line to new file
> for line in text:
> if len(line) > 1 and line[-2] in ';,-':
> line = line.rstrip()
> output.write(line)
> else: output.write(line)
> 
> print "Data written to cleandata.txt."
> 
> # close the files
> in_file.close()
> output.close()
> 
> As written above it tells me that there are 0 lines which is surprising 
> because if I run the first part by itself it tells there are 1982 lines 
> ( actually 1983 so i am figuring EOF)
> It copies/writes the data to the cleandata file but it does not strip 
> out CR and put data on one line ( a sample of what i am trying to get is 
> next)
> 
> A.-C. Manufacturing Company. (See Sebastian, A. A., and Capes, assignors.)
> 
> 
> My apologies if i have intruded.

Please reply on-list in the future.

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


Re: [Tutor] Should I use python for parsing text

2007-03-22 Thread Luke Paireepinart
Jay Mutter III wrote:
> Luke;
I'm a bit pressed for time right now and I can't look over this e-mail.
Please reply on-list in the future using the 'reply-all' feature.  
You're more likely to get a prompt response.
(this e-mail is  carbon copied to the list, so don't worry about sending 
another.)
>
> Actually it did help but the following
>
> for line in text:
> if len(line) > 1 and line[-2] in ';,-':
> line = line.rstrip()
> output.write(line)
> else: output.write(line)
>
> does not have any apparent effect on my data.
>
> I start with lines
>
>
> A.-C. Manufacturing Company. (See Sebastian, A. A.,
> and Capes, assignors.)
> A. G. A. Railway Light & Signal Co. (See Meden, Elof
> H„ assignor.)
> A-N Company, The. (See Alexander and Nasb, as-
> signors.;
> AN Company, The. (See Nash, It. J., and Alexander, as-
> signors.)
> A/S. Arendal Smelteverk.(See Kaaten, Einar, assignor.)
> A/S. Bjorgums Gevaei'kompani. (See Bjorguni, Nils, as-
> signor.)
> A/S  Mekano. (Sec   Schepeler,   Herman  A.,  assignor.)
> A/S Myrens Verkstad.(See Klling, Jens W. A., assignor.)
> A/S Stordo Kisgruber. (See Nielsen, C., and Ilelleland,
> assignors.)
>
> and I end up with the same.
> My goal is to strip out the CR or LF or whatever so that all info for 
> one entity is on 1 line.
>
> Any ideas of where i am going wrong?
>
> Thanks
>
> Jay
>
>
> On Mar 21, 2007, at 1:41 AM, Luke Paireepinart wrote:
>
>>
>>> # The next 5 lines are so I have an idea of how many lines i started 
>>> with in the file.
>>>
>>> in_filename = raw_input('What is the COMPLETE name of the file you 
>>> want to open:')
>>> in_file = open(in_filename, 'r')
>>> text = in_file.read()
>> read() returns a one-dimensional list with all the data, not a 
>> 2-dimensional one with each element a line.
>> Use readlines() for this functionality.
>> (Eg. A file with contents 'hello\nhoware\nyou?' would have this 
>> string returned by read(), but
>> readlines() would return ['hello\n','howare\n','you?'].)
>>> num_lines = text.count('\n')
>> or just len(text) if you're using readlines()
>>> print 'There are', num_lines, 'lines in the file', in_filename
>>>
>>> output = open("cleandata.txt","a")# file for writing data to 
>>> after stripping newline character
>> You might want to open this file in 'write' mode while you're 
>> testing, so previous test results don't confuse you.
>>>
>>> # read file, copying each line to new file
>>> for line in text:
>> since read() returns a 1-dimensional list, you're looping over every 
>> character in the file, not every line.
>>> if line[:-1] in '-':
>> In this case this is the same as "if line == '-':" because your 
>> 'line' variable only contains characters.
>>> line = line.rstrip()
>>> output.write(line)
>>> else: output.write(line)
>>>
>>> print "Data written to cleandata.txt."
>>>
>>> # close the files
>>> in_file.close()
>>> output.close()
>>>
>>> The above ran with no erros, gave me the number of lines in my 
>>> orginal file but then when i opened the cleandata.txt file
>>> I got:
>>>
>>> A.-C.䴀愀渀甀昀愀挀琀甀爀椀渀最 �Company.⠀匀攀攀�Sebastian,䄀⸀�A., 
>>> �and 䌀愀瀀攀猀Ⰰ�assignors.)�A.䜀⸀�A.刀愀椀氀眀愀礀 �Light☀�Signal䌀 
>>> 漀⸀� (See䴀攀搀攀渀Ⰰ�Elof�Hassignor.)�A-N䌀漀洀瀀愀渀礀Ⰰ�The.⠀匀攀 
>>> 攀 �Alexander愀渀搀�Nasb,愀猀ⴀ�猀椀最渀漀爀猀⸀㬀�䄀一�Company,吀栀攀 
>>> ⸀� (See一愀猀栀Ⰰ�It.䨀⸀Ⰰ�and䄀氀攀砀愀渀搀攀爀Ⰰ�as-�
>> Not sure what caused all of those characters.
>> HTH,
>> -Luke
>
>

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


Re: [Tutor] MONEY MATTERS

2007-03-22 Thread Kent Johnson
Kirk Bailey wrote:
> ok, SHOULD THIS BE A THREAD OR A SEPERATE LIST?
> 
> Many of ius are independants, and write code for the love of it- or to 
> promote and sell independantly. So possibly a thread discussing ways to 
>   turn useful code into moiney is a useful idea. If the wish of the list 
> is a thread here, we can do that, or we can start a seperate list for 
> it. What are the wishes of this list?

That is definitely not appropriate for this list. This list has a very 
clear purpose which is to provide a place for people to ask and answer 
beginner questions about Python.

My guess is that there are already lists or web sites devoted to your 
idea, have you looked?

Kent

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


Re: [Tutor] MONEY MATTERS

2007-03-22 Thread Kirk Bailey
So be it.

The list now exists, and is called Coding4Cash.

Here is a weblink to it:
http://tech.groups.yahoo.com/group/coding4cash/

And here are email address':
Post message:   [EMAIL PROTECTED]
Subscribe:  [EMAIL PROTECTED]
Unsubscribe:[EMAIL PROTECTED]
List owner: [EMAIL PROTECTED]

SPAM need not apply. Hackers, hobbyists, pros, guru's and them what know 
better but do it anyway for the hell of it are all welcome.

This thread is ended in peace and respect; let all who wish come forth 
to discuss scratching the itch that our wallet does not yet contain.


Steve Oldner wrote:
> My 2 cents worth is to set up something separate, it'll just keep the
> principles and ideas clearer.  While I have my own ideas about the
> "million dollar application", I would like a forum where I can just
> listen and learn any type of ideas without having a worry that someone
> will 'steal' my idea and beat me to the market.
> 
> I work for a state government supporting a SAP HR application, so
> anything I learn from this list is not directly applicable to my job.
> However, the ideas and logic to solve various PYTHON solutions is a big
> benefit in expanding my search for alternative solutions.
> 
> And one day, I will have free time to work on my "million dollar app."
> (LOL!)
> 
> Thanks,
> 
> Steve Oldner  
> 
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
> Behalf Of Kirk Bailey
> Sent: Wednesday, March 21, 2007 10:14 PM
> To: tutor@python.org
> Subject: [Tutor] MONEY MATTERS
> 
> ok, SHOULD THIS BE A THREAD OR A SEPERATE LIST?
> 
> Many of ius are independants, and write code for the love of it- or to
> promote and sell independantly. So possibly a thread discussing ways to
>   turn useful code into moiney is a useful idea. If the wish of the list
> is a thread here, we can do that, or we can start a seperate list for
> it. What are the wishes of this list?
> 

-- 
Salute!
-Kirk Bailey
   Think
  +-+
  | BOX |
  +-+
   knihT

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


Re: [Tutor] Money Matters

2007-03-22 Thread Jaggo
Hello!

I read this list because I'm new to Python and I really am learning an average 
of something new I did not know from every digest hitting my inbox.

I have no interest on the matter of money.

Just my .02$.

-Omer Tabach

[EMAIL PROTECTED] wrote:
Message: 3
Date: Wed, 21 Mar 2007 23:13:57 -0400
From: Kirk Bailey 
Subject: [Tutor] MONEY MATTERS
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

ok, SHOULD THIS BE A THREAD OR A SEPERATE LIST?

Many of ius are independants, and write code for the love of it- or to 
promote and sell independantly. So possibly a thread discussing ways to 
  turn useful code into moiney is a useful idea. If the wish of the list 
is a thread here, we can do that, or we can start a seperate list for 
it. What are the wishes of this list?

-- 
Salute!
 -Kirk Bailey
   Think
  +-+
  | BOX |
  +-+
   knihT

Fnord.


 
-
Don't pick lemons.
See all the new 2007 cars at Yahoo! Autos.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] sorting data from multiple arrays

2007-03-22 Thread Jeff Peery
hello, I typically run into this problem and I'm not always sure of the most 
efficient way to handle it. I often work with multiple arrays of data, say 
arrays a, b, and c, and I want to sort the elements of b and c based on a. for 
example:

a = [3,2,1,4]
b = ['hi', 'my','name', 'is']
c = [5,2,4,2]

I order 'a' from small to large and do the same rearrangement to 'b' and 'c':
a = [1,2,3,4]
 b = ['name', 'my','hi', 'is']
 c = [4,2,5,2]

usually I do some terrible looking for loops and iterate over the whole 
mess is there a clean, efficient way to do this, or is there a nice 
function that would reorder the elements of b and c based on the soring of a?

thanks

 
-
Don't be flakey. Get Yahoo! Mail for Mobile and 
always stay connected to friends.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Why is it...

2007-03-22 Thread Jay Mutter III
Why is it that when I run the following interactively

f = open('Patents-1920.txt')
line = f.readline()
while line:
 print line,
 line = f.readline()
f.close()

I get an error message

File "", line 4
 f.close()
 ^
SyntaxError: invalid syntax

but if i run it in a script there is no error?

Thanks

Jay

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


[Tutor] [ANN] Python courses this Spring

2007-03-22 Thread wesley chun
I'll be giving a variety of Python courses this Spring.  Daytime
courses are for visitors and locals who need Python training in the
shortest amount of time possible via consecutive workdays.  Python is
certainly gaining momentum as our February course filled up
completely!  Although I had planned on scheduling the same set to be
taught in November, it is likely that these May daytime sessions are
the last ones of 2007.

In contrast, I'm experimenting with a *weekly evening* course in
Silicon Valley designed mainly for locals.  It represents a viable
alternative to those who cannot take time off during the week as well
as being more budget-friendly, as I am partnering with a local
community college (Foothill) to offer this course.  Class takes place
on the main campus and you must register through the college to
attend.

For more information, such as cost and other course details, see the
corresponding websites below. Contact me privately if you have any
more questions.

cheers,
-wesley

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

DAYTIME
===
- (Intensive) Introduction to Python (Mon-Wed, May 14-16)
- Advanced Python Programming (Wed-Fri, May 16-18)
- Advanced Python (short course; Thu-Fri, May 17-18)
- Core Python (Intro+Advanced combo; Mon-Fri, May 14-18)

These courses run daily 9a-5p and will take place in San Bruno right
near the San Francisco International Airport at the:

Staybridge Suites - San Francisco Airport
1350 Huntington Ave
San Bruno, CA  94066 USA
http://www.ichotelsgroup.com/h/d/sb/1/en/hd/sfobr

Discounts are available for students and teachers, as well as multiple
registrations from those working at the same company.  For more info
and registration, go to http://cyberwebconsulting.com (click on
"Python Training")

LOCALS: free parking and 101/280/380 access, BART across the street
and CalTrain down the road (San Bruno stations)

VISITORS: free hotel shuttle to/from the San Francisco airport, lots
of free food and wireless, 2-bedroom suites w/private baths and a
common work/living area available for traveling coworkers, and of
course, The City by the Bay
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

EVENING
===
- Intermediate Python Programming (Tues, Apr 10-Jun 26)

This course will cover the same topics as the advanced course above as
well as critical portions of the intensive introductory course. It
will be held once a week on Tuesday evenings from 6-9:40p.

Foothill College
12345 El Monte Road
Los Altos Hills, CA  94022 USA
(right off 280, just south of Stanford)

http://www.foothill.edu/schedule/schedule.php
search for CIS 68L for Spring Quarter 2007
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sorting data from multiple arrays

2007-03-22 Thread R. Alan Monroe
> hello, I typically run into this problem and I'm not always sure of the most 
> efficient way to handle it. I often work with multiple arrays of data, say 
> arrays a, b, and c, and I want to sort the
> elements of b and c based on a. for example:

> a = [3,2,1,4]
> b = ['hi', 'my','name', 'is']
> c = [5,2,4,2]

> I order 'a' from small to large and do the same rearrangement to 'b' and 'c':
> a = [1,2,3,4]
>  b = ['name', 'my','hi', 'is']
>  c = [4,2,5,2]

> usually I do some terrible looking for loops and iterate over the whole 
> mess is there a clean, efficient way to do this, or is there a nice 
> function that would reorder the elements of b and c
> based on the soring of a?

Is switching to a dictionary an option?

mystuff = {3: ('hi', 5),
   2: ('my', 2),
   1: ('name', 4),
   4: ('is', 2)}

You can get a list of the keys, sort _that_, then fetch from the dict
based on the sorted list.

Alan

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


Re: [Tutor] Why is it...

2007-03-22 Thread Kent Johnson
Jay Mutter III wrote:
> Why is it that when I run the following interactively
> 
> f = open('Patents-1920.txt')
> line = f.readline()
> while line:
>  print line,
>  line = f.readline()
> f.close()
> 
> I get an error message
> 
> File "", line 4
>  f.close()
>  ^
> SyntaxError: invalid syntax
> 
> but if i run it in a script there is no error?

Can you copy/paste the actual console transcript?

BTW a better way to write this is
f = open(...)
for line in f:
 print line,
f.close()

Kent

> 
> Thanks
> 
> Jay
> 
> ___
> 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] Why is it...

2007-03-22 Thread Jason Massey

In the interpreter this doesn't work:


f = open(r"c:\python24\image.dat")
line = f.readline()
while line:

... line = f.readline()
... f.close()
Traceback (  File "", line 3
   f.close()
   ^
SyntaxError: invalid syntax

But this does:


f = open(r"c:\python24\image.dat")
line = f.readline()
while line:

... line = f.readline()
...

f.close()



Note the differing placement of the f.close() statement, it's not part of
the while.


On 3/22/07, Kent Johnson <[EMAIL PROTECTED]> wrote:


Jay Mutter III wrote:
> Why is it that when I run the following interactively
>
> f = open('Patents-1920.txt')
> line = f.readline()
> while line:
>  print line,
>  line = f.readline()
> f.close()
>
> I get an error message
>
> File "", line 4
>  f.close()
>  ^
> SyntaxError: invalid syntax
>
> but if i run it in a script there is no error?

Can you copy/paste the actual console transcript?

BTW a better way to write this is
f = open(...)
for line in f:
 print line,
f.close()

Kent

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

___
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] sorting data from multiple arrays

2007-03-22 Thread Kent Johnson
Jeff Peery wrote:
> hello, I typically run into this problem and I'm not always sure of the 
> most efficient way to handle it. I often work with multiple arrays of 
> data, say arrays a, b, and c, and I want to sort the elements of b and c 
> based on a. for example:
> 
> a = [3,2,1,4]
> b = ['hi', 'my','name', 'is']
> c = [5,2,4,2]
> 
> I order 'a' from small to large and do the same rearrangement to 'b' and 
> 'c':
> a = [1,2,3,4]
> b = ['name', 'my','hi', 'is']
> c = [4,2,5,2]
> 
> usually I do some terrible looking for loops and iterate over the whole 
> mess is there a clean, efficient way to do this, or is there a nice 
> function that would reorder the elements of b and c based on the soring 
> of a?

Decorate-sort-undecorate 
(http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52234)
to the rescue:

In [12]: a = [3,2,1,4]
In [13]: b = ['hi', 'my','name', 'is']
In [14]: c = [5,2,4,2]
In [15]: temp = zip(a, b, c)
In [16]: temp
Out[16]: [(3, 'hi', 5), (2, 'my', 2), (1, 'name', 4), (4, 'is', 2)]
In [17]: temp.sort()
In [18]: _, b, c = zip(*temp)
In [19]: b
Out[19]: ('name', 'my', 'hi', 'is')
In [20]: c
Out[20]: (4, 2, 5, 2)

Or, if you are a fan of one-liners:
In [21]: _, b, c = zip(*sorted(zip(a, b, c)))

Methinks there should be a clever way to do this with the key= argument 
to sort, but I can't think of it at the moment...

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


Re: [Tutor] sorting data from multiple arrays

2007-03-22 Thread Jeff Peery
Thanks for all the responses, that is a huge help!

Jeff

Kent Johnson <[EMAIL PROTECTED]> wrote: Jeff Peery wrote:
> hello, I typically run into this problem and I'm not always sure of the 
> most efficient way to handle it. I often work with multiple arrays of 
> data, say arrays a, b, and c, and I want to sort the elements of b and c 
> based on a. for example:
> 
> a = [3,2,1,4]
> b = ['hi', 'my','name', 'is']
> c = [5,2,4,2]
> 
> I order 'a' from small to large and do the same rearrangement to 'b' and 
> 'c':
> a = [1,2,3,4]
> b = ['name', 'my','hi', 'is']
> c = [4,2,5,2]
> 
> usually I do some terrible looking for loops and iterate over the whole 
> mess is there a clean, efficient way to do this, or is there a nice 
> function that would reorder the elements of b and c based on the soring 
> of a?

Decorate-sort-undecorate 
(http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52234)
to the rescue:

In [12]: a = [3,2,1,4]
In [13]: b = ['hi', 'my','name', 'is']
In [14]: c = [5,2,4,2]
In [15]: temp = zip(a, b, c)
In [16]: temp
Out[16]: [(3, 'hi', 5), (2, 'my', 2), (1, 'name', 4), (4, 'is', 2)]
In [17]: temp.sort()
In [18]: _, b, c = zip(*temp)
In [19]: b
Out[19]: ('name', 'my', 'hi', 'is')
In [20]: c
Out[20]: (4, 2, 5, 2)

Or, if you are a fan of one-liners:
In [21]: _, b, c = zip(*sorted(zip(a, b, c)))

Methinks there should be a clever way to do this with the key= argument 
to sort, but I can't think of it at the moment...

Kent


 
-
Finding fabulous fares is fun.
Let Yahoo! FareChase search your favorite travel sites to find flight and hotel 
bargains.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] pruning and ordering a list of lists

2007-03-22 Thread William O'Higgins Witteman
I have a list of lists derived from a log file that I want to create a
summary of, but I am not sure of an approach to do what I need.

Here's a sample of the data:

[["user1","18/Mar/2007:07:52:38 -0400"],["user1","18/Mar/2007:07:52:40 
-0400"],["user2","18/Mar/2007:07:52:42 -0400"],["user3","18/Mar/2007:07:52:42 
-0400"],["user2","18/Mar/2007:07:52:43 -0400"]]

What I want as output is something like this:

[["first user alphabetically","most recent timestamp for this user"],["second 
user alphabetically","most recent timestamp for this user"], ...]

Can anyone suggest an approach for this?  Thanks.
-- 

yours,

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


[Tutor] Another string question

2007-03-22 Thread Jay Mutter III
I wanted the following to check each line and if it ends in a right  
parentheses then write the entire line to one file and if not then  
write the line to anther.
It wrote all of the ) to one file and the rest of the line (ie minus  
the ) to the other file.


in_filename = raw_input('What is the COMPLETE name of the file you  
would like to process?')
in_file = open(in_filename, 'rU')
text = in_file.read()
count = len(text.splitlines())
print "There are ", count, 'lines to process in this file'
out_filename1 = raw_input('What is the COMPLETE name of the file in  
which you would like to save Companies?')
companies = open(out_filename1, 'aU')
out_filename2 = raw_input('What is the COMPLETE name of the file in  
which you would like to save Inventors?')
patentdata = open(out_filename2, 'aU')
for line in text:
 if line[-1] in ')':
 companies.write(line)
 else:
 patentdata.write(line)
in_file.close()
companies.close()
patentdata.close()

Thanks

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


Re: [Tutor] Why is it...

2007-03-22 Thread Terry Carroll
On Thu, 22 Mar 2007, Jason Massey wrote:

> In the interpreter this doesn't work:
> 
> >>> f = open(r"c:\python24\image.dat")
> >>> line = f.readline()
> >>> while line:
> ... line = f.readline()
> ... f.close()
> Traceback (  File "", line 3
> f.close()
> ^
> SyntaxError: invalid syntax

The interactive interpreter was expecting a blank line to end the suite of
the compound statement.  Without the blank line, it interpreted the close
statement to be part of the suite;  and since it's not indented as the
suite should be, it's a syntax error.

The blank line requirement is only in interactive sessions:

  Note that a (top-level) compound statement must be followed by a 
  blank line in interactive mode; this is needed to help the parser
  detect the end of the input.

 http://docs.python.org/ref/interactive.html

> But this does:
> 
> >>> f = open(r"c:\python24\image.dat")
> >>> line = f.readline()
> >>> while line:
> ... line = f.readline()
> ...
> >>> f.close()
> >>>
> 
> Note the differing placement of the f.close() statement, it's not part of
> the while.

The difference is that this time you gave it the blank line to end the 
suite.


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


Re: [Tutor] sorting data from multiple arrays

2007-03-22 Thread Jeff Peery
... what is '*' in '*temp'? thanks!
J

Kent Johnson <[EMAIL PROTECTED]> wrote: Jeff Peery wrote:
> hello, I typically run into this problem and I'm not always sure of the 
> most efficient way to handle it. I often work with multiple arrays of 
> data, say arrays a, b, and c, and I want to sort the elements of b and c 
> based on a. for example:
> 
> a = [3,2,1,4]
> b = ['hi', 'my','name', 'is']
> c = [5,2,4,2]
> 
> I order 'a' from small to large and do the same rearrangement to 'b' and 
> 'c':
> a = [1,2,3,4]
> b = ['name', 'my','hi', 'is']
> c = [4,2,5,2]
> 
> usually I do some terrible looking for loops and iterate over the whole 
> mess is there a clean, efficient way to do this, or is there a nice 
> function that would reorder the elements of b and c based on the soring 
> of a?

Decorate-sort-undecorate 
(http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52234)
to the rescue:

In [12]: a = [3,2,1,4]
In [13]: b = ['hi', 'my','name', 'is']
In [14]: c = [5,2,4,2]
In [15]: temp = zip(a, b, c)
In [16]: temp
Out[16]: [(3, 'hi', 5), (2, 'my', 2), (1, 'name', 4), (4, 'is', 2)]
In [17]: temp.sort()
In [18]: _, b, c = zip(*temp)
In [19]: b
Out[19]: ('name', 'my', 'hi', 'is')
In [20]: c
Out[20]: (4, 2, 5, 2)

Or, if you are a fan of one-liners:
In [21]: _, b, c = zip(*sorted(zip(a, b, c)))

Methinks there should be a clever way to do this with the key= argument 
to sort, but I can't think of it at the moment...

Kent


 
-
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] basics of passing arguments to make a graph

2007-03-22 Thread Che M
Hi, this is some *really* beginner Python stuff, hope you folks could help 
me.


I've been trying to make basic plots (line graphs) using the pyplot module 
(wx.lib.plot) in wxPython.  So far, so good.  To start, I can use a class 
like this (adapted from a demo) to draw a pre-defined graph:


class PlotPanel(wx.lib.plot.PlotCanvas):
   def __init__(self, *args, **kwargs):
   wx.lib.plot.PlotCanvas.__init__(self, *args, **kwargs) 
#PlotCanvas on which I draw graph
   self.Draw(self._drawGraph())   
#draw it using the next function


   def _drawGraph(self):   #this 
function draws just this one specific graph
   points = [(1,1), (3,4), (5,7), (7,14)] #just four points 
for a simple little line graph

   m=[]
   m.append(wx.lib.plot.PolyLine(points))  #uses the 
points to make a line
   m.append(wx.lib.plot.PolyMarker(points))   #uses the 
points to place markers
   return wx.lib.plot.PlotGraphics(m, "Graph Title",  #return the 
whole graph with title, etc.

   "x axis", "y axis")

This makes a nice graph, but the problem is that doing it this way means I 
need a seperate class for every graph I would want to make.  Obviously not 
the way to do it.


What I want instead is a way to have a class that makes my graphs but which 
expects to be passed points from some other place, in my case, due to some 
user choice (in selecting data from a list or whatever).


I get the sense that the idea is to pass a list of points to the drawGraph 
function.  Is that right?  So far I've fooled with it but can't get it to 
work.  Mostly because I don't understand argument passing well at all (like 
the *args, **kwargs stuff is still mysterious to me).  I was hoping this 
could help touch on some good principles for how to do this type of argument 
passing generally.


Thank you,
Che

_
It’s tax season, make sure to follow these few simple tips 
http://articles.moneycentral.msn.com/Taxes/PreparationTips/PreparationTips.aspx?icid=HMMartagline


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