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 = [
,
,
,
,

]

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?

Recommended Answers

All 12 Replies

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.

Is your idea to have Python create an HTML file that you can look at in your browser?

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'] ('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.

Now I have a question. Where is Calendar.py?

Sorry, the attachment didnt work last time. Here the files are.

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!

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.

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>'

Another thing is that when you use split, it returns as a string. I need to return this as a list? Im very usure.

returnlines.append((currentline.replace'"','')).currentline.replace('\n','').split(','))

This looks like an entry into the soon to be published "Python Puzzle" book. I am lost with that one too!

Take a good look at the "Starting Python" sticky, there is an explanation for the pickle module. Come to think of it, this would make your task much easier. If you have any questions with pickle, please ask.

To do multiple replacements you can do it sequentially, for example ...

currentline = "'Line 1','Line 1 Across 1','<br>','<br>','<br>','<br>'"
print currentline  # test
currentline = currentline.replace('L','l')
currentline = currentline.replace('A','a')
print currentline  # test

Another thing is that when you use split, it returns as a string. I need to return this as a list? Im very usure.

split(separator) returns a list of separated items (whatever the designated separator is) , there is also splitlines() that returns a list of lines (here \n is the separator).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.