[Tutor] How to extract data from text to excel?

2011-03-03 Thread tee chwee liong
hi, i found a module called xlwt (http://www.python-excel.org/) that can write to Excel. i want the code to read from a file (robert.txt) and then write to excel in a column. for eg: cell col0, row0 = 0 cell col0, row1 = 0 cell col0, row2 = 0 cell col0, row3 = 1 cell col0, row4 = 0 cell col0,

Re: [Tutor] A class that instantiates conditionally ?

2011-03-03 Thread Steven D'Aprano
David wrote: class MyClass_2(object): def __new__(self, condition): if condition: return object.__new__(self) else: return None [...] Spot on. It would require two "if" tests, one inside __new__() and another in the code. You will always need a

Re: [Tutor] How to extract data from text to excel?

2011-03-03 Thread Steven D'Aprano
tee chwee liong wrote: hi, i found a module called xlwt (http://www.python-excel.org/) that can write to Excel. i want the code to read from a file (robert.txt) and then write to excel in a column. for eg: cell col0, row0 = 0 cell col0, row1 = 0 cell col0, row2 = 0 cell col0, row3 = 1 cell col

Re: [Tutor] How to extract data from text to excel?

2011-03-03 Thread Joel Goldstick
On Thu, Mar 3, 2011 at 9:10 AM, Steven D'Aprano wrote: > tee chwee liong wrote: > >> hi, >> i found a module called xlwt (http://www.python-excel.org/) that can >> write to Excel. i want the code to read from a file (robert.txt) and then >> write to excel in a column. for eg: >> cell col0, row0

[Tutor] Help!

2011-03-03 Thread Andrew Bouchot
okay so this is my comp sci lab * Problem: *ProductionTime.py It takes exactly 2 minutes and 7 second to produce an item. Unfortunately, after 143 items are produced, the fabricator must cool off for 5 minutes and 13 seconds before it can continue. Write a program that will calculate the amount o

Re: [Tutor] Help!

2011-03-03 Thread Knacktus
Am 03.03.2011 22:28, schrieb Andrew Bouchot: okay so this is my comp sci lab * Problem: *ProductionTime.py It takes exactly 2 minutes and 7 second to produce an item. Unfortunately, after 143 items are produced, the fabricator must cool off for 5 minutes and 13 seconds before it can continue. W

Re: [Tutor] Help!

2011-03-03 Thread James Reynolds
This isn't so much as a python problem as it is a simple math problem, and I feel you are being lazy, but in the offchance you're having problems with the '/' operator: cooloff = (numitems/143)*313 total = cooloff + seconds I think you are using python 2.6 (and I guess 2.7) or older based on you

Re: [Tutor] Help!

2011-03-03 Thread David Hutto
On Thu, Mar 3, 2011 at 4:56 PM, Knacktus wrote: > Am 03.03.2011 22:28, schrieb Andrew Bouchot: >> >> okay so this is my comp sci lab >> * >> >> Problem: >> >> *ProductionTime.py It takes exactly 2 minutes and 7 second to produce an >> item. Unfortunately, after 143 items are produced, the fabricat

[Tutor] Homework Problem Flaming (was: Help!)

2011-03-03 Thread Corey Richardson
On 03/03/2011 04:58 PM, James Reynolds wrote: > You are almost assuredly going to get flamed for not having a descriptive > title and for asking what is obviously homework questions > Maybe for not having a descriptive title, but there's nothing wrong with coming to the list with homework! The r

Re: [Tutor] Help!

2011-03-03 Thread Steven D'Aprano
James Reynolds wrote: [...] You are almost assuredly going to get flamed for not having a descriptive title and for asking what is obviously homework questions At least Andrew did the right thing by being honest that it was a homework question, and by showing the work he's done so far. But y

Re: [Tutor] How to extract data from text to excel?

2011-03-03 Thread tee chwee liong
> What does this comment mean? You don't have any commas in the file > "robert.txt", and you don't actually do anything with or to commas in > your code. I think that comment is false. > > > L = line.strip() > > sheet.write(row,0,L) > > Here you write the entire contents of the file into one

Re: [Tutor] How to extract data from text to excel?

2011-03-03 Thread Steven D'Aprano
tee chwee liong wrote: What does this comment mean? You don't have any commas in the file "robert.txt", and you don't actually do anything with or to commas in your code. I think that comment is false. L = line.strip() sheet.write(row,0,L) Here you write the entire contents of the file into

Re: [Tutor] How to extract data from text to excel?

2011-03-03 Thread tee chwee liong
thanks Steven, i get what you mean now. final code works: import xlwt """Reads robert.txt""" # Create workbook and worksheet wbk = xlwt.Workbook() sheet = wbk.add_sheet('python') row = 0 # row counter f = open('robert.txt') L = line.strip() for c in L: sheet.write(row,0,c)

[Tutor] Need some help on output

2011-03-03 Thread Becky Mcquilling
I am creating a dictionary by parsing a text file. The code is below: backup_servers = {} fo = open('c:/test/backup_shares.txt') for line in fo: backup_server = line.split(',') backup_servers[backup_server[0]]=backup_server[1] for i, v in backup_servers.items(): backup_shares = i archive

Re: [Tutor] Need some help on output

2011-03-03 Thread Kushal Kumaran
On Fri, Mar 4, 2011 at 6:48 AM, Becky Mcquilling wrote: > I am creating a dictionary by parsing a text file. > > The code is below: > backup_servers = {} > fo = open('c:/test/backup_shares.txt') > for line in fo: >   backup_server = line.split(',') >   backup_servers[backup_server[0]]=backup_serve

Re: [Tutor] Need some help on output

2011-03-03 Thread Becky Mcquilling
Thanks, that helped. I took a second look and realized where I had tried calling the .strip() method was wrong. Appreciate the pointer. Becky On Thu, Mar 3, 2011 at 5:37 PM, Kushal Kumaran < kushal.kumaran+pyt...@gmail.com> wrote: > On Fri, Mar 4, 2011 at 6:48 AM, Becky Mcquilling > wrote: >