[Zope] upload a file to a folder using a variable for folder names
Casey Duncan
casey@zope.com
Thu, 5 Sep 2002 10:41:15 -0400
Please don't cross-post (python list removed)
On Thursday 05 September 2002 04:38 am, michael.ta=F1ag wrote:
> Hi!
>=20
> I'm uploading a file to a particular folder in Zope using a form. For
> example I need to upload celebrants.txt to 2002/august/birthday
> so what I did (from a script by runyaga- thanks!)
>=20
> context.2002.august.birthday.manage_addFile()
>=20
> 1. error when I use '2002' so I changed it to 'yr2002'
> (why can't I use '2002'?) code now becomes
>=20
> context.yr2002.august.birthday.manage_addFile()
Although '2002' is a legal Zope id, it is not a legal identifier in Pytho=
n.=20
Identifiers must start with a letter. To get around this, use the getitem=
=20
notation:
context['2002'].august.blah.blah
>=20
> 2. The month and year are hard coded. What if I want it to be=20
> supplied by the user. So my idea is to use a variable.
> for example
> month =3D month_value
> year =3D year_value
>=20
> code becomes
> context.year.month.birthday.manage_addFile()
>=20
> for example
> if month_value is september and year is yr2002 code should read
> context.yr2002.september.birthday.manage_addFile()
> =20
> =20
> but this produces an error. I think python sees year and month
> as folder names.
Same thing, use the getitem notation:
context[year][month].birthday.manage_addFile()
Where year and month are variables.
hth,
-Casey