web app breakage with utf-8

2006-07-06 Thread elmo
Hello, after two days of failed efforts and googling, I thought I had
better seek advice or observations from the experts. I would be grateful
for any input.

We have various small internal web applications that use utf-8 pages for
storing, searching and retrieving user input. They have worked fine for
years with non ASCII values, including Russian, Greek and lots of accented
characters. They still do on an old version of python (2.2.1), and there's
nothing in the code to decode/encode the input, it's *just worked*.

Recently however, while testing on a dev machine, I notice that any
characters outside ASCII are causing SQL statement usage to break with
UnicodeDecodeError exceptions with newer versions of python (2.3 and 2.4).
There are a number of threads online, suggesting converting to unicode
types, and similar themes, but I'm having no success. I am probably
completely misunderstaning something fundamental. :-( 

My first question is did something change for normal byte stream usage
making it more strict? I'm surprised there aren't more problems
like this online.

Is there a correct way to handle text input from a  when the page is
utf-8 and that input is going to be used in SQL statements? I've tried
things like (with no success): 
sql = u"select * from blah where col='%s'" % input

Doing sql = sql.decode('latin1') prior to execution prevents the
some UnicodeDecodeError exceptions, but the data retrieved from the tables
is no longer usable, causing breakage when being used to create the output
for the browser.


I really am at a loss for what is going wrong, when everything works fine
on crusty old 2.2.1. What are others doing for caputre, store, and output
for web utf-8?


Rgds,
Jason

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: web app breakage with utf-8

2006-07-06 Thread elmo
On Thu, 06 Jul 2006 19:16:53 +0200, Stefan Behnel wrote:
>> 
>> Is there a correct way to handle text input from a  when the page is
>> utf-8 and that input is going to be used in SQL statements? I've tried
>> things like (with no success): 
>> sql = u"select * from blah where col='%s'" % input
> 
> What about " ... % unicode(input, "UTF-8")" ?
> 
> 

I guess it's similar, I've had partial success with input.decode('utf-8')
before DB usage, and then output.encode('utf-8') for output. But although
this stores and displays newly added utf-8 texts correctly, it
causes other problems when displaying the existing texts. I think
they're suffering from a double encoding issue. It seems rather
strange the encode/decode appears to be required now, and not before.
Is this how it should be done?



> 
> You didn't tell us what database you are using, which encoding your
> database uses, which Python-DB interface library you deploy, and lots of
> other things that might be helpful to solve your problem.

That would be MySQLdb with latin1, but I've tried various methods to make
it utf-8 (lots of guidance online). But this was only after I discovered
the breakage with the newer python. I.e. it has worked for years on both
machines and various python versions. I omitted that info because I can
paste the SQL into mysql's shell, it does the expected thing with no
errors, so I assumed the DB itself isn't the cause. I guess it could 
be a new MySQLdb issue causing breakage.


I feel I can see part of the light, but if I'm close to what I think
is needed, it's not practical to change everything to handle encode/decode
site wide, especially as some of the data gets moved to Oracle for other
applications (most is written in Perl).



I'm thinking I need to do this now, is this the norm?:

get user input from web
text.encode('utf-8')
store or use as search in DB
text.decode('utf-8')
display page etc

The encode/decode stages have never been required before :-(


> 
> Stefan

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: web app breakage with utf-8

2006-07-06 Thread elmo
On Thu, 06 Jul 2006 19:41:32 +, elmo wrote:
> I guess it could be a new MySQLdb issue causing breakage.
> 

Replying to self, this is *very* close to the problem:


http://sourceforge.net/tracker/index.php?func=detail&aid=1438913&group_id=22307&atid=374932
-- 
http://mail.python.org/mailman/listinfo/python-list


A strange and annoying restriction, possibly a bug. A glance by a more experienced would be nice.

2005-06-25 Thread Elmo Mäntynen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

This is the case:

>>> n=(100,) tuple(*n)

Traceback (most recent call last):
  File "", line 1, in -toplevel-
tuple(*n)
TypeError: iteration over non-sequence

To be sure I searched for ways to check if something is a sequence:

>>> n.__iter__().next()
100
>>> n.__getitem__(0)
100
>>> iter(n).next()
100

So as you see, as far as I can see, I gave a sequence, but the
Traceback says the opposite.
To me it seems like a bug, but I haven't filed any bugs before, so a
little help wouldn't be bad. I haven't checked if there is bug for
this, but I don't consider me finding a bug as obvious as this very
propable and something like this not to be fixed a long time ago.

I tried this with python 2.3 and 2.4.

If possible, could you send any anwsers to my own address also. Thanks
in advance.
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCvdUActNFyQJObrsRAha+AJ9oEyL7sufkXCcsQxuMDvyxNqvGGACglBrF
le8HmOgXAyRqAY3DASArjM4=
=F9NR
-END PGP SIGNATURE-

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I need help figuring out how to fix this code.

2005-06-28 Thread Elmo Mäntynen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Nathan Pinno wrote:
>   Hi all,
> 
>   I need help figuring out how to fix my code. I'm using Python 2.2.3, and
> it keeps telling me invalid syntax in the if name == "Nathan" line. Here is
> the code if you need it.
> 
>   #This program asks for a password, then asks for the user's name after the
> correct password has been supplied. The computers response will vary,
>   # depending on the name inputted.
>   print "Program Author: Nathan Pinno"
>   print "ID# 2413448"
>   print
>   print "Program 3 - Loops and IF Conditions"
>   print
>   password = raw_input("Type in the password, please: ")
>   while password != "hello":
>   print "Incorrect password!"
>   print "Welcome to the second half of the program!"
>   name = raw_input("What is your name, please? ")
>   if name == "Nathan":
>   print "What a great name!"
>   elif name == ["Madonna", "Cher"]:
>   print "May I have your autograph please!"
>   else
>   print name,", that's a nice name!"
> 
>   What's wrong with the code? How do I fix it, so that it works?
> 
>   Thanks,
>   Nathan Pinno
>   http://www.npinnowebsite.ca/
> 
> 
> 
I think about all the problems in your code are solved by suggestions
sent before me, but I have some advice for future situations:

Especially with more complex problems, larger code blocks using external
libs, etc, you should, if appropriate, include the Traceback, some
explanation on the given code(what it should do etc.) and maybe consider
documenting the code a little with comments and docstrings(try reading
some code you haven't seen before or in a long time, without any
commentation. What about debugging it without knowing what the code is
supposed to do?) Don't be intimidated by this, you just seemed to be new
with programming with python and thought of sharing this with you. You
have maybe read something like this before from a book or tutorial(there
are a couple of good free books for learning python, for example "byte
of python"), but good commenting and the like are usually appreciated
only when they're not available:)

Hope I didn't scare you. Happy tinkering with python!

Elmo Mäntynen
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCweCuctNFyQJObrsRAuXsAJ0auOEcnZDZB/A8hLHNS7D5C1Rl2ACfQNp1
7PAZLqG7H/6Fv6hC2m9CO50=
=cesa
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Set/Get attribute syntatic sugar

2005-06-28 Thread Elmo Mäntynen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Peter Hansen wrote:
> Заур Шибзухов wrote:
> 
>> There is a syntactic sugar for item access in
>> dictionaries and sequences:
>>
>> o[e] = v <-> o.__setitem__(e, v)
>> o[e] <-> o.__getitem__(e)
>>
>> where e is an expression.
>>
>> There is no similar way for set/get attribute for objects.
>> If e is a given name, then  o.e = v <-> o.__setattr__(e, v)
>> o.e <-> o.__getattr__(e)
>>
>> Anybody thought about this issue?
> 
> 
> Perhaps not, but now that you've pointed it out they've taken the time
> machine back and fixed the problem before it arose:

Maybe funny, but a bit too cocky for my taste. Robert kern is propably
right about what he really meant so don't be too hasty in the future,
right?). Looking at his code example I got the picture that he's of the
kind that could come up with something useful. So either he's
right(which I think is the case), or it's just the kind of silly mistake
all of us sometimes make. I sure think some one should look in to this
suggestion.

 class C:
> ...   def __setattr__(self, e, v):
> ... print 'setting %s to %s' % (e, v)
> ... self.__dict__[e] = v
> ...
 o = C()
 v = 'mystring'
 o.e = v
> setting e to mystring
 o.e
> 'mystring'

> 
> -Peter
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCweYyctNFyQJObrsRAhGtAJwJXlhQ9i1PIQKj1fus6GIq7mfDVgCeJBRw
vq6yJrozRTUSTu+p8akVbVw=
=k4EW
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Having trouble importing against PP2E files

2005-07-08 Thread Elmo Mäntynen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Charles Krug wrote:
> List:
> 
> I'm trying to use the example files from Programming Python, 2nd Ed.
> 
> I've copied them into c:\Python24\Examples\PP2E.
> 
> Launching any of the examples programs by themselves seems to work
> spiffily.
> 
> Using regedit, I appended "c:\Python24\Examples\PP2E" to Pythonpath
> 
> from the immediate window, executing the line:
> 
> from PP2E.launchmodes import PortableLauncher
> 
> Raises the exception:
> 
> Import Error: no module named PP2E.launchmodes
> 
> However if I copy launchmodes.py into my work directory, it imports
> successfully.
> 
> Both "Examples" above and "Examples\PP2E" contain the __init__.py file.
Are both Examples and PP2E packages? In python if a folder is meant to
represent a package it should iclude the above mentioned file
__init__.py and by saying the above your suggesting that PP2E is a
package inside the package Examples.
> 
> Obviously, I'm missing a setup step here.
> 
> What magic do I need to perform to get Python to find modules in the
> Examples heirarchy?
> 
> Is there any way to check from the immediate window where Python will
> search for modules?  Pythonpath appears to be correct, but the file
> isn't importing unless I copy it to the current directory.
> 
> Thanx
> 
> 
> Charles
> 
If the above is correct, you should append the pythonpath with
c:\Python24\ and refer to the wanted .py with Examples.PP2E.launchmodes.
As such the import statement obviously should be "from
Examples.PP2E.launchmodes import PortableLauncher". If the above isn't
the case and there is still something unclear about this, reply with a
more detailed post about the situation.

Elmo
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCztd7ctNFyQJObrsRAuXNAJwLF94iM0IwkJVHLUOo1EEBYQg6FACfQFfE
jcxspYU80N5MSZB9uqhbBh4=
=YquD
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Searching for metadata related tools for use with python

2005-07-13 Thread Elmo Mäntynen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

I'm interested in various metadata
extraction/prosessing/distribution/something tools(including ways of
differentiating between files, eg hashing etc) and especially python
enabled ones. I'm also considering content-recognition/differentiating
eg. image recognition. I'm already aware of these: python-bitzi,
python-musicbrainz, mmpython, IMDbPY, python-mhash and imgSeek. If you
could point me to other relating resources it would be great.

Elmo
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFC1Q3WctNFyQJObrsRAjXbAJ92B53YC9NqtC9nymK07OL+L3mNTwCgmlbb
dPfSDsqJzBh+xa3h5L28Qac=
=AtAo
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Searching for metadata related tools for use with python

2005-07-13 Thread Elmo Mäntynen
On Wed, 13 Jul 2005 15:49:27 +0300, Elmo Mäntynen wrote:

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
> 
> I'm interested in various metadata
> extraction/prosessing/distribution/something tools(including ways of
> differentiating between files, eg hashing etc) and especially python
> enabled ones. I'm also considering content-recognition/differentiating
> eg. image recognition. I'm already aware of these: python-bitzi,
> python-musicbrainz, mmpython, IMDbPY, python-mhash and imgSeek. If you
> could point me to other relating resources it would be great.
> 
> Elmo
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.1 (GNU/Linux)
> Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
> 
> iD8DBQFC1Q3WctNFyQJObrsRAjXbAJ92B53YC9NqtC9nymK07OL+L3mNTwCgmlbb
> dPfSDsqJzBh+xa3h5L28Qac=
> =AtAo
> -END PGP SIGNATURE-

I would also like comments if you're pretty sure the aren't any other
reöated resources. Anything related to organizing one's
filecollections(be it music, photos, books etc.), though i'm not
particularly interested in another mp3/ogg-tagger(report it still
though, if you will).

Elmo
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Multivariable polynomials

2005-07-13 Thread Elmo Mäntynen
On Tue, 12 Jul 2005 18:56:30 -0700, Chris wrote:

> Does anyone know of a good standalone implementation of multivariable
> polynomials in python?
> 
> Thanks,
> Chris

I'm interested also, and am posting this in the hope that being now a
multipostthread with a plus sign next to it, someone more knowledgeable
would see it and answer our mutual request:)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Searching for metadata related tools for use with python

2005-07-13 Thread Elmo Mäntynen
On Wed, 13 Jul 2005 15:49:27 +0300, Elmo Mäntynen wrote:

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
> 
> I'm interested in various metadata
> extraction/prosessing/distribution/something tools(including ways of
> differentiating between files, eg hashing etc) and especially python
> enabled ones. I'm also considering content-recognition/differentiating
> eg. image recognition. I'm already aware of these: python-bitzi,
> python-musicbrainz, mmpython, IMDbPY, python-mhash and imgSeek. If you
> could point me to other relating resources it would be great.
> 
> Elmo
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.1 (GNU/Linux)
> Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
> 
> iD8DBQFC1Q3WctNFyQJObrsRAjXbAJ92B53YC9NqtC9nymK07OL+L3mNTwCgmlbb
> dPfSDsqJzBh+xa3h5L28Qac=
> =AtAo
> -END PGP SIGNATURE-

I would also like comments if you're pretty sure the aren't any other
related resources. Anything related to organizing one's
filecollections(be it music, photos, books etc.), though i'm not
particularly interested in another mp3/ogg-tagger(report it still
though, if you will), would be interesting also.

Elmo

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Searching for metadata related tools for use with python

2005-07-13 Thread Elmo Mäntynen
On Wed, 13 Jul 2005 23:22:01 +0300, Elmo Mäntynen wrote:

> On Wed, 13 Jul 2005 15:49:27 +0300, Elmo Mäntynen wrote:
> 
>> -BEGIN PGP SIGNED MESSAGE-
>> Hash: SHA1
>> 
>> I'm interested in various metadata
>> extraction/prosessing/distribution/something tools(including ways of
>> differentiating between files, eg hashing etc) and especially python
>> enabled ones. I'm also considering content-recognition/differentiating
>> eg. image recognition. I'm already aware of these: python-bitzi,
>> python-musicbrainz, mmpython, IMDbPY, python-mhash and imgSeek. If you
>> could point me to other relating resources it would be great.
>> 
>> Elmo
>> -BEGIN PGP SIGNATURE-
>> Version: GnuPG v1.4.1 (GNU/Linux)
>> Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
>> 
>> iD8DBQFC1Q3WctNFyQJObrsRAjXbAJ92B53YC9NqtC9nymK07OL+L3mNTwCgmlbb
>> dPfSDsqJzBh+xa3h5L28Qac=
>> =AtAo
>> -END PGP SIGNATURE-
> 
> I would also like comments if you're pretty sure the aren't any other
> related resources. Anything related to organizing one's
> filecollections(be it music, photos, books etc.), though i'm not
> particularly interested in another mp3/ogg-tagger(report it still
> though, if you will), would be interesting also.
> 
> Elmo

I'm going for completeness(though a never-ending chase you might say).

Elmo
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Searching for metadata related tools for use with python

2005-07-13 Thread Elmo Mäntynen
On Wed, 13 Jul 2005 23:25:46 +0300, Elmo Mäntynen wrote:

> On Wed, 13 Jul 2005 23:22:01 +0300, Elmo Mäntynen wrote:
> 
>> On Wed, 13 Jul 2005 15:49:27 +0300, Elmo Mäntynen wrote:
>> 
>>> -BEGIN PGP SIGNED MESSAGE-
>>> Hash: SHA1
>>> 
>>> I'm interested in various metadata
>>> extraction/prosessing/distribution/something tools(including ways of
>>> differentiating between files, eg hashing etc) and especially python
>>> enabled ones. I'm also considering content-recognition/differentiating
>>> eg. image recognition. I'm already aware of these: python-bitzi,
>>> python-musicbrainz, mmpython, IMDbPY, python-mhash and imgSeek. If you
>>> could point me to other relating resources it would be great.
>>> 
>>> Elmo
>>> -BEGIN PGP SIGNATURE-
>>> Version: GnuPG v1.4.1 (GNU/Linux)
>>> Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
>>> 
>>> iD8DBQFC1Q3WctNFyQJObrsRAjXbAJ92B53YC9NqtC9nymK07OL+L3mNTwCgmlbb
>>> dPfSDsqJzBh+xa3h5L28Qac=
>>> =AtAo
>>> -END PGP SIGNATURE-
>> 
>> I would also like comments if you're pretty sure the aren't any other
>> related resources. Anything related to organizing one's
>> filecollections(be it music, photos, books etc.), though i'm not
>> particularly interested in another mp3/ogg-tagger(report it still
>> though, if you will), would be interesting also.
>> 
>> Elmo
> 
> I'm going for completeness(though a never-ending chase you might say).
> 
> Elmo

RDF(or xml otherwise) enabled metadata repositories/etc. are of interest
to me also(musicbrainz and bitzi are recognized already). If just someone
said something instead of this thread being completely ignored. If this
isn't the place to discuss something like this would someone point me to
a better one.

Elmo
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Multivariable polynomials

2005-07-14 Thread Elmo Mäntynen
On Wed, 13 Jul 2005 16:55:32 -0700, Chris wrote:

> Fantastic. May I ask what you are hoping to use it for?
> 
> I checked out Scientific python:
> http://starship.python.net/~hinsen/ScientificPython/
> 
> It has a module with multivariate polynomials with support for a good
> functionality but I think the input style won't suit my needs. In any
> case, perhaps it will be helpful for you.
> 
> Chris

Nothing at the moment:) Just plain interested. Maybe in the future. I'm
focused on an area bit different at the moment(My post's a couple ones
after this one).

-- 
http://mail.python.org/mailman/listinfo/python-list


Differences between RDFlib - 4RDF and Redfoot - 4Suite?

2005-07-14 Thread Elmo Mäntynen
I was wondering about the differences with the referred libs and servers.
Since the documentation isn't so thorough(and a bit because of my laziness),
I thought I'd make request for usage accounts etc. stating the pros and
cons of the aforementioned. Any notes would be appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Differences between RDFlib - 4RDF and Redfoot - 4Suite?

2005-07-19 Thread Elmo Mäntynen
On Fri, 15 Jul 2005 09:50:38 -0700, uche.ogbuji wrote:

> I'd say for now if you just need quick RDF parsing, and you're not also
> using plain XML, and stuff like Versa RDF query language aren't
> important to you, you'll get along just fine with rdflib.

Thanks for the insight!

-- 
http://mail.python.org/mailman/listinfo/python-list


How can I get an sha1 hash in base32?

2005-07-23 Thread Elmo Mäntynen
I know how to make a hash(using mhash), but instead of encoded as hex I
want it in base32 for use with the bitzi catalog. python-bitzi is useful
but way too slow for just getting the hash of a file(am going to use it
elsewhere). Thanks.

Elmo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I get an sha1 hash in base32?

2005-07-24 Thread Elmo Mäntynen
On Sat, 23 Jul 2005 23:27:44 +0200, Marc 'BlackJack' Rintsch wrote:

> In <[EMAIL PROTECTED]>, Elmo Mäntynen wrote:
> 
>> I know how to make a hash(using mhash), but instead of encoded as hex I
>> want it in base32 for use with the bitzi catalog. python-bitzi is useful
>> but way too slow for just getting the hash of a file(am going to use it
>> elsewhere). Thanks.
> 
> Doesn't Bitzi calculate some kind of audio fingerprint?  Just a hash of
> the file would result in very different hash values for different codecs,
> bitrates etc. for the "same" audio data.
> 
> Ciao,
>   Marc 'BlackJack' Rintsch

I don't think it does, but musicbrainz is designed for just that, and
there's a ptyhon binding for using the libs.

Elmo
-- 
http://mail.python.org/mailman/listinfo/python-list

How can I encode something in base32 preferably very fast?

2005-07-25 Thread Elmo Mäntynen
I want to encode a plaindigest or a hexdigest in base 32. Any hints?

Elmo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I encode something in base32 preferably very fast?

2005-07-25 Thread Elmo Mäntynen
On Mon, 25 Jul 2005 16:51:05 +0200, Johannes Findeisen wrote:

> On Mon, 2005-07-25 at 17:23 +0300, Elmo Mäntynen wrote:
>> I want to encode a plaindigest or a hexdigest in base 32. Any hints?
> 
> Search Google for "python base32" isn't as hard...
> 
> First result are the original python lib documentation:
> http://docs.python.org/lib/module-base64.html
> 
> I think  you need to convert to a String before encoding... 
> 
> Have fun,

I thought I had looked at that particular module:). Thanks for pointing it
out.

Elmo 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How can I encode something in base32 preferably very fast?

2005-07-25 Thread Elmo Mäntynen
On Mon, 25 Jul 2005 21:15:36 +0300, Elmo Mäntynen wrote:

> On Mon, 25 Jul 2005 16:51:05 +0200, Johannes Findeisen wrote:
> 
>> On Mon, 2005-07-25 at 17:23 +0300, Elmo Mäntynen wrote:
>>> I want to encode a plaindigest or a hexdigest in base 32. Any hints?
>> 
>> Search Google for "python base32" isn't as hard...
>> 
>> First result are the original python lib documentation:
>> http://docs.python.org/lib/module-base64.html
>> 
>> I think  you need to convert to a String before encoding... 
>> 
>> Have fun,
> 
> I thought I had looked at that particular module:). Thanks for pointing it
> out.
> 
> Elmo

I'm using python2.3(because of my distro of choise, debian) and did a
help(base64) and of course didn't see anything about base32:). Now i have
good reason to change to 2.4:) Thanks

Elmo

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Dictionary inheritance

2005-08-13 Thread Elmo Mäntynen
On Fri, 12 Aug 2005 12:44:11 -0700, Talin wrote:

> I want to make a dictionary that acts like a class, in other words, 
> supports inheritance: If you attempt to find a key that isn't present, 
> it searches a "base" dictionary, which in turn searches its base, and so on.
> 
> Now, I realize its fairly trivial to code something like this using 
> UserDict, but given that classes and modules already have this behavior, 
> is there some built-in type that already does this?
> 
> (This is for doing nested symbol tables and such.)
> 
> ---

You could always do:

class nestedDict(dict):
...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: class-call a function in a function -problem

2005-08-16 Thread Elmo Mäntynen
On Tue, 16 Aug 2005 18:45:51 +0200, wierus wrote:

>  Hello, i have a problem. I write my first class in python so i'm not a 
> experience user.  I want to call a function in another function, i tried to 
> do it in many ways, but i always failed:(
> I supposed it's sth very simple but i can't figure what it is:
> ==
> class ludzik:
>  x=1
>  y=2
>  l=0 
#is this L or I^?
>  def l(self): 
#What about this^. You are strongly advised to use more obvious and more
easily distinguishable names.
>   ludzik.l=ludzik.x+ludzik.y
>   print ludzik.l
This is a normal instance method ^

> 
>  def ala(self):
>   print ludzik.x
>   print ludzik.y
>   ludzik.l()
If call normal method through a class you get an unbound method, so you
have to provide explicitly an instance of that class: ludzik.l(self). If
you don't want to do that, go read about class methods in the official
tutorial.

> 
> 
> z=ludzik()
> z.ala()
> 
> 
> 
> k.py
> 1
> 2
> Traceback (most recent call last):
>   File "k.py", line 17, in ?
> z.ala()
>   File "k.py", line 14, in ala
> ludzik.l()
> TypeError: unbound method l() must be called with ludzik instance as
> first argument (got nothing instead)
> 
> 
> i would be gratefull for resolving this problem for me

Elmo
-- 
http://mail.python.org/mailman/listinfo/python-list


How to lock files (the easiest/best way)?

2006-07-15 Thread Elmo Mäntynen
Is there something better than using fnctl? It seems a bit intimidating
with a quick look.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to lock files (the easiest/best way)?

2006-07-15 Thread Elmo Mäntynen
On Sat, 15 Jul 2006 23:28:21 +0200, Sybren Stuvel wrote:

> Elmo Mäntynen enlightened us with:
>> Is there something better than using fnctl? It seems a bit
>> intimidating with a quick look.
> 
> Locking files is a complex business. What do you want to lock? Why?
> Lock it with respect to what? It's easier to lock a file for local
> use, compared to when the file also has to be locked from, say, use
> via the network.
> 
> Sybren

Only locally. I want to be able to read/write to a single file from
multiple possibly parallel processes. Would 'touch lock' (or something
like that) work reliably (this just occured to me)?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to lock files (the easiest/best way)?

2006-07-15 Thread Elmo Mäntynen
On Sat, 15 Jul 2006 23:52:10 +0200, Sybren Stuvel wrote:

> Elmo Mäntynen enlightened us with:
>> Only locally. I want to be able to read/write to a single file from
>> multiple possibly parallel processes. Would 'touch lock' (or
>> something like that) work reliably (this just occured to me)?
> 
> I use a lock directory for that, os.mkdir('/var/lock/somedir').
> If you use a file, you need two steps:
> 1) Check whether the lock-file exists
> 2) Create the lock-file
> 
> This is not atomic. With a directory, creating it will fail if it
> already exists. This means you can atomically check for the lock, and
> if it doesn't exist already, you've immediately created it too.
> 
> Sybren

Thanks. Is that what atomic basically means?
-- 
http://mail.python.org/mailman/listinfo/python-list