| | |
Returning a correct python list
Thread Solved |
•
•
Join Date: May 2005
Posts: 5
Reputation:
Solved Threads: 0
Hi,
I have the following interface for a 35 day month calander script that I am writing. The interface is called for use with an html page. I am supposed to collect user input which includes day, month and their event.
blankEventsJan = [
['<br>','<br>','<br>','<br>','<br>','<br>','<br>'],
['<br>','<br>','<br>','<br>','<br>','<br>','<br>'],
['<br>','<br>','<br>','<br>','<br>','<br>','<br>'],
['<br>','<br>','<br>','<br>','<br>','<br>','<br>'],
['<br>','<br>','<br>','<br>','<br>','<br>','<br>']
]
I have already collected user input to tell me what day, month and event is required. Now I need a way to insert the user info into the correct month and return the month in the same interface forum as above. I have tried to create a new file which has a line(35) for each day, I have found ways of reading the lines but cannot seem to get it to return the above tamplate form. nested lists are giving me problems.
What I was hoping to do was create a separate calander file for each month, gather user input, select the correct calander month for reading , editing it with users events and then writing it back to file.
Any ideas?
I have the following interface for a 35 day month calander script that I am writing. The interface is called for use with an html page. I am supposed to collect user input which includes day, month and their event.
blankEventsJan = [
['<br>','<br>','<br>','<br>','<br>','<br>','<br>'],
['<br>','<br>','<br>','<br>','<br>','<br>','<br>'],
['<br>','<br>','<br>','<br>','<br>','<br>','<br>'],
['<br>','<br>','<br>','<br>','<br>','<br>','<br>'],
['<br>','<br>','<br>','<br>','<br>','<br>','<br>']
]
I have already collected user input to tell me what day, month and event is required. Now I need a way to insert the user info into the correct month and return the month in the same interface forum as above. I have tried to create a new file which has a line(35) for each day, I have found ways of reading the lines but cannot seem to get it to return the above tamplate form. nested lists are giving me problems.
What I was hoping to do was create a separate calander file for each month, gather user input, select the correct calander month for reading , editing it with users events and then writing it back to file.
Any ideas?
What is the output you're currently getting? That may help us determine where the hang-up is. Additionally, if you don't mind posting the actual code you're using to display the calendar, that would probably help.
Also, have you considered using a table with invisible borders, rather than trying to display it like you're doing? Just a thought, as you could create a 7 column by 5 row table, and populate it pretty easily.
Also, have you considered using a table with invisible borders, rather than trying to display it like you're doing? Just a thought, as you could create a 7 column by 5 row table, and populate it pretty easily.
Alex Cavnar, aka alc6379
•
•
Join Date: May 2005
Posts: 5
Reputation:
Solved Threads: 0
Hi,
Thanks for replying so soon. Yes this has to output html to a browser. Attached is a copy of the scrip that creates the calander and the file containing the days for a month of feb. You will see that in the code I have defined the jan month as the template is above and it works fine. I then put the same template in blankEventsFeb.py, read it and it comes out wrong.
To run the code, run calander.py which will read file blankEventsFeb. It creates an html filed called MyCalander.html
If you look at the getEvents() function, blankEvents1 = createEvents(), blankEvents1 =
[['hello'], ['2'], ['3'], ['4'], ['5'], ['6'], ['7'], ['8'], ['9'], ['10'], ['11'], ['12'], ['13'], ['14'], ['15'], ['16'], ['17'], ['18'], ['19'], ['20'], ['21'], ['22'], ['23'], ['24'], ['25'], ['26'], ['27'], ['28'], ['29'], ['30'], ['31'], ['32'], ['33'], ['34'], ['35'], 'hello'] ('hello' was folr testing.)
this is were I have become stuck, its just not returning the correct for of data in the list. The getEvents() is all still under contruction.
I have also included the user input (events.py) but im still working on that too.
Thanks for replying so soon. Yes this has to output html to a browser. Attached is a copy of the scrip that creates the calander and the file containing the days for a month of feb. You will see that in the code I have defined the jan month as the template is above and it works fine. I then put the same template in blankEventsFeb.py, read it and it comes out wrong.
To run the code, run calander.py which will read file blankEventsFeb. It creates an html filed called MyCalander.html
If you look at the getEvents() function, blankEvents1 = createEvents(), blankEvents1 =
[['hello'], ['2'], ['3'], ['4'], ['5'], ['6'], ['7'], ['8'], ['9'], ['10'], ['11'], ['12'], ['13'], ['14'], ['15'], ['16'], ['17'], ['18'], ['19'], ['20'], ['21'], ['22'], ['23'], ['24'], ['25'], ['26'], ['27'], ['28'], ['29'], ['30'], ['31'], ['32'], ['33'], ['34'], ['35'], 'hello'] ('hello' was folr testing.)
this is were I have become stuck, its just not returning the correct for of data in the list. The getEvents() is all still under contruction.
I have also included the user input (events.py) but im still working on that too.
Your major problem is your data file. It looks very much like a list, but when you read it in, it's a string that looks like a list of five lists. Yet it is a string!
The solution is very similar to:
http://www.daniweb.com/techtalkforums/thread22614.html
after the minor surgery. Just to help you troubleshoot temporarily print out the two lists blankEventsJan and blankEventsFeb. Comment those out later.
My initial suggestion would be to save the events as five lines of data separated by commas, then use f.readlines() and split() just like in the other thread. Then append the resulting five lists into one.
Your events.py must generate the proper data file of course. If a comma delimiter interferes with your data content, use something more exotic like a ~
I keep fiddling too!
The solution is very similar to:
http://www.daniweb.com/techtalkforums/thread22614.html
after the minor surgery. Just to help you troubleshoot temporarily print out the two lists blankEventsJan and blankEventsFeb. Comment those out later.
My initial suggestion would be to save the events as five lines of data separated by commas, then use f.readlines() and split() just like in the other thread. Then append the resulting five lists into one.
Your events.py must generate the proper data file of course. If a comma delimiter interferes with your data content, use something more exotic like a ~
I keep fiddling too!
May 'the Google' be with you!
•
•
Join Date: May 2005
Posts: 5
Reputation:
Solved Threads: 0
Hi,
Thanks for the tips, im working through it but need to know:
How to replace more then one item at once in this function ie i want to remove " and \n from the list
def readMonth():
f = open('blankEventsFeb.py')
returnlines = []
for currentline in f.readlines():
if not currentline.startswith('#'):
(here) returnlines.append((currentline.replace'"','')).currentline.replace('\n','').split(','))
f.close()
print returnlines
return returnlines
If i do this im sure that the new file attached will read in correclty as 5 lists within a list.
The new feb file looks like this, ive added text to help me address the days
'line 1','line 1 across 1','<br>','<br>','<br>','<br>','<br>'
'line 2','line 2 across 2','<br>','<br>','<br>','<br>','<br>'
'line 3','<br>','<br>','<br>','<br>','<br>','<br>'
'<br>','<br>','<br>','<br>','<br>','<br>','<br>'
'<br>','<br>','<br>','<br>','<br>','<br>','<br>'
Thanks for the tips, im working through it but need to know:
How to replace more then one item at once in this function ie i want to remove " and \n from the list
def readMonth():
f = open('blankEventsFeb.py')
returnlines = []
for currentline in f.readlines():
if not currentline.startswith('#'):
(here) returnlines.append((currentline.replace'"','')).currentline.replace('\n','').split(','))
f.close()
print returnlines
return returnlines
If i do this im sure that the new file attached will read in correclty as 5 lists within a list.
The new feb file looks like this, ive added text to help me address the days
'line 1','line 1 across 1','<br>','<br>','<br>','<br>','<br>'
'line 2','line 2 across 2','<br>','<br>','<br>','<br>','<br>'
'line 3','<br>','<br>','<br>','<br>','<br>','<br>'
'<br>','<br>','<br>','<br>','<br>','<br>','<br>'
'<br>','<br>','<br>','<br>','<br>','<br>','<br>'
![]() |
Other Threads in the Python Forum
- Previous Thread: Sort an Inventory List (Python)
- Next Thread: Do I need to upgrade Python?
| Thread Tools | Search this Thread |
abrupt ansi anti apache approximation array assignment avogadro backend beginner binary bluetooth book builtin calculator character code converter countpasswordentry curved customdialog dan08 dictionaries dictionary dynamic examples exe file float format function gnu graphics gui heads homework ideas import inches input java launcher library line lines linux list lists loop mouse mysqlquery number numbers numeric output parsing path phonebook plugin pointer port prime programming progressbar projects py2exe pygame python random recursion redirect scrolledtext software statictext statistics string strings sum table terminal text textarea thread threading time tlapse trick tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable wordgame write wxpython xlib






