Basic Class/Instance Question

2007-05-23 Thread Siah
Ready to go insane here. Class A, taking on a default value for a
variable. Instantiating two separate objects of A() gives me a shared
val list object. Just see the example bellow:


class A(object):
def __init__(self, val=[]):
self.val=val

obj1 = A()
obj2 = A()

print obj1 is obj2   # False - as expected
print obj1.val is obj2.val # True! - Why... oh god WHY


---
Using python 2.4. Is this a bug with this version of python? How can I
trust the rest of the universe is still in place? Could she still like
me? Many questions I have. Lets start with the python problem for now.

Thanks,
Sia

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


Re: Basic Class/Instance Question

2007-05-23 Thread Siah
I think that's because:

>>> [] is []
False
>>> () is ()
True

--
Sia

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


Re: Basic Class/Instance Question

2007-05-23 Thread Siah
Bruno,

I got my lesson today, first get your morning coffee before posting
and of course avoid mutable objects as default arguments. Silly post,
perhaps. Good to hear universe is in place. I should have rtffaq,
though that's not why she left...

Sia

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


How to Split a String

2007-11-29 Thread Siah
Hi,

I need to convert the string: '(a, b, "c", d, "e")' into the following
list ['a', 'b', 'c', 'd', 'e']. Much like a csv reader does. I usually
use the split function, but this mini-monster wouldn't properly get
split up due to those random quotations postgresql returns to me.

Please help me with this,
Thanks,
Sia
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to Split a String

2007-11-29 Thread Siah
The basic split/strip method wouldn't split '(a, b, "c,...", d)',
which is why I chose not to use it.

The csv solution seems to work well, that helped me much here (thank
you), but I am looking to see if I can get it solved with some regular
expression. This is how far I've come so far, but it needs much work:
re.compile('"*,"*').split(x[1:-1])

Thanks for your help,
Sia




On Nov 29, 3:24 pm, Bjoern Schliessmann  wrote:
> Siah wrote:
> > I need to convert the string: '(a, b, "c", d, "e")' into the
> > following list ['a', 'b', 'c', 'd', 'e']. Much like a csv reader
> > does. I usually use the split function, but this mini-monster
> > wouldn't properly get split up due to those random quotations
> > postgresql returns to me.
>
> I heavily suggest you to look at the docs -- those are very basic
> functions.
>
> http://docs.python.org/lib/string-methods.html
>
> One solution might be:
>
> >>> results = []
> >>> for part in '(a, b, "c", d, "e")'.split(","):
>
> ...  part = part.strip()
> ...  part = part.strip("(),\"")
> ...  part = part.strip()
> ...  results.append(part)
> ...>>> print results
>
> ['a', 'b', 'c', 'd', 'e']
>
>
>
> Regards,
>
> Björn
>
> --
> BOFH excuse #285:
>
> Telecommunications is upgrading.

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


Re: How to Split a String

2007-11-29 Thread Siah
Thanks Mr. Edwards, I went ahead and started using the csv reader.
Sia
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to Split a String

2007-11-30 Thread Siah
> I hope you don't use Python to access the database, get a tuple back,
> convert it to a string and then try to break up that string into a list!?

Sadly, that is the case. Well, kinda. I'm using psycopg2 to access
postgresql, which is great. Though postgres has more features than
psycopg2 supports, such as nested arrays within a row, that psycopg2
provides to me as a string, which leaves it to me to try to make sense
out of it. I hate it, its dirty and uncool, but oh well.

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


How to Setup SFTP Server using twisted

2008-11-29 Thread Siah
The only implementation I could find is mangled with Zope. Anyone has
any resources handy on the subject?

Thank you in advanced,
Sia
--
http://mail.python.org/mailman/listinfo/python-list


Re: Strings and % sign fails - Help Please

2006-03-24 Thread Siah
Problem Solved.  The problem was with psycopg.Binary whose mere job is
to convert bytes into clear text for sql statement.  I'll be filing a
bug.

Thanks everyone,
Sia

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


What is Caching my DB

2006-03-27 Thread Siah
I just launched my django site for a client.  My problem is something
is caching my db data in a bizzar way.  Here are some of the behaviours
I get:

- I login, and every other page it makes me login again for a 5 minutes
or so and then it remembers that I am logged in.
- I add a record, it reflects it to the site in close to 5 minutes from
now
- Every other DB related change takes some time to reflect

My temporary domain is (a #  # a# r #m # i #n   d o t##c o# m).
Please remove (#, space, and replace dot with .). To see this for
yourself login to the site by going to /admin/ with username and
password: django

Thanks,
Sia

ps. django rocks

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


Re: What is Caching my DB

2006-03-27 Thread Siah
Sorry, this post had to go on Django Users group. I'll post it there.
You may ignore this post here.

Sia

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


Re: What is Caching my DB

2006-03-27 Thread Siah
Helpful Hints Ivan. Thanks for the points.
Sia

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