944,103 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 8278
  • Python RSS
You are currently viewing page 1 of this multi-page discussion thread
May 6th, 2005
0

Returning a correct python list

Expand Post »
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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
warriorwarren is offline Offline
5 posts
since May 2005
May 6th, 2005
0

Re: Returning a correct python list

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.
Team Colleague
Reputation Points: 186
Solved Threads: 147
Cookie... That's it
alc6379 is offline Offline
2,519 posts
since Dec 2003
May 6th, 2005
0

Re: Returning a correct python list

Is your idea to have Python create an HTML file that you can look at in your browser?
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
May 7th, 2005
0

Re: Returning a correct python list

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
warriorwarren is offline Offline
5 posts
since May 2005
May 7th, 2005
0

Re: Returning a correct python list

Now I have a question. Where is Calendar.py?
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
May 8th, 2005
0

Re: Returning a correct python list

Sorry, the attachment didnt work last time. Here the files are.
Attached Files
File Type: zip New WinRAR ZIP archive.zip (3.4 KB, 27 views)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
warriorwarren is offline Offline
5 posts
since May 2005
May 8th, 2005
0

Re: Returning a correct python list

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!
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
May 10th, 2005
0

Re: Returning a correct python list

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.
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
May 10th, 2005
0

Re: Returning a correct python list

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>'
Reputation Points: 10
Solved Threads: 0
Newbie Poster
warriorwarren is offline Offline
5 posts
since May 2005
May 10th, 2005
0

Re: Returning a correct python list

Another thing is that when you use split, it returns as a string. I need to return this as a list? Im very usure.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
warriorwarren is offline Offline
5 posts
since May 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Sort an Inventory List (Python)
Next Thread in Python Forum Timeline: Darken/Lighten an Image (Python)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC