Returning a correct python list

Thread Solved

Join Date: May 2005
Posts: 5
Reputation: warriorwarren is an unknown quantity at this point 
Solved Threads: 0
warriorwarren warriorwarren is offline Offline
Newbie Poster

Returning a correct python list

 
0
  #1
May 6th, 2005
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?
Reply With Quote Quick reply to this message  
Join Date: Dec 2003
Posts: 2,414
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Solved Threads: 123
Team Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: Returning a correct python list

 
0
  #2
May 6th, 2005
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.
Alex Cavnar, aka alc6379
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,972
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 920
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Returning a correct python list

 
0
  #3
May 6th, 2005
Is your idea to have Python create an HTML file that you can look at in your browser?
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 5
Reputation: warriorwarren is an unknown quantity at this point 
Solved Threads: 0
warriorwarren warriorwarren is offline Offline
Newbie Poster

Re: Returning a correct python list

 
0
  #4
May 7th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,972
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 920
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Returning a correct python list

 
0
  #5
May 7th, 2005
Now I have a question. Where is Calendar.py?
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 5
Reputation: warriorwarren is an unknown quantity at this point 
Solved Threads: 0
warriorwarren warriorwarren is offline Offline
Newbie Poster

Re: Returning a correct python list

 
0
  #6
May 8th, 2005
Sorry, the attachment didnt work last time. Here the files are.
Attached Files
File Type: zip New WinRAR ZIP archive.zip (3.4 KB, 6 views)
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,972
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 920
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Returning a correct python list

 
0
  #7
May 8th, 2005
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!
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,972
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 920
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Returning a correct python list

 
0
  #8
May 10th, 2005
Almost forgot, if you want to save a list and get it back as a list you have to use the pickle.dump() and pickle.load() functions.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 5
Reputation: warriorwarren is an unknown quantity at this point 
Solved Threads: 0
warriorwarren warriorwarren is offline Offline
Newbie Poster

Re: Returning a correct python list

 
0
  #9
May 10th, 2005
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>'
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 5
Reputation: warriorwarren is an unknown quantity at this point 
Solved Threads: 0
warriorwarren warriorwarren is offline Offline
Newbie Poster

Re: Returning a correct python list

 
0
  #10
May 10th, 2005
Another thing is that when you use split, it returns as a string. I need to return this as a list? Im very usure.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC