423,336 Members | 1,194 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,336 IT Pros & Developers. It's quick & easy.

problem with a css cycler

P: n/a
Hello all
I am trying to build a css cycler in python, to change the css used in a
website every X number of days, using a list of files: the first X days
it'd show file1, then file2, then file3, then back to the first one.

The code I came up with is the following:

css = ["file1", "file2", "file3"]
i = 0
max_i = 3
today = int(raw_input("today's date: "))
stored_day = 1

if 3 <= (today - stored_day):
stored_day = today
i += 1
if i > max_i:
i = 0
print "Variable today is %s .\n" % today
print "Variable stored_day is %s .\n" % stored_day
print "Variable i is %s .\n" % i
print "Variable css is now %s \n" % css[i]
----------
The problem with this is that it works only for the first X days. How do
I make it "keep state" for the next iterations?

Thanks
--
Adriano Varoli Piazza
The Inside Out: http://moranar.com.ar
ICQ: 4410132
MSN: ad*******@hotmail.com
Claves gpg / pgp en hkp://subkeys.pgp.net

Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Adriano Varoli Piazza wrote:
Hello all
I am trying to build a css cycler in python, to change the css used in a
website every X number of days, using a list of files: the first X days
it'd show file1, then file2, then file3, then back to the first one.

The code I came up with is the following:

css = ["file1", "file2", "file3"]
i = 0 max_i = 3 remove the above line, you might forget updating max_i someday when you
change the css list - len(css) is less errorprone.
today = int(raw_input("today's date: "))
stored_day = 1
days = today - stored_day
i = days % len(css)
print "Variable today is %s .\n" % today
print "Variable stored_day is %s .\n" % stored_day
print "Variable i is %s .\n" % i
print "Variable css is now %s \n" % css[i]
----------
The problem with this is that it works only for the first X days. How do
I make it "keep state" for the next iterations?

Thanks


The % "modulo" operator gives you the rest of an integer division, e. g:
for i in range(10): .... print i, "% 3 =", i % 3
....
0 % 3 = 0
1 % 3 = 1
2 % 3 = 2
3 % 3 = 0
4 % 3 = 1
5 % 3 = 2
6 % 3 = 0
7 % 3 = 1
8 % 3 = 2
9 % 3 = 0


Peter

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.