Checking if a variable is a dictionary

2008-03-06 Thread Guillermo

Hello,

This is my first post here. I'm getting my feet wet with Python and I
need to know how can I check whether a variable is of type dictionary.

Something like this:

if isdict(a) then print "a is a dictionary"

Regards,

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


Re: Checking if a variable is a dictionary

2008-03-06 Thread Guillermo

Wow, I think I'm gonna like this forum. Thank you all for the prompt
answers!

>What makes you say you "need" to know this ? Except for a couple corner
>cases, you usually don't need to care about this. If you told us more
>about the actual problem (instead of asking about what you think is the
>solution), we might be of more help...

Good point.

I want to iterate recursively a dictionary whose elements might be
strings or nested tuples or dictionaries and then convert values to a
tagged format according to some rules.

d = {'a':"i'm a", 'b':(1,2,3),'c':{'a':"i'm a",'x':"something",'y':
('a','b','c')}}

I'm just designing the algorithm, but I think Python dictionaries can
hold any kind of sequence?

Regards,

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


Re: Checking if a variable is a dictionary

2008-03-06 Thread Guillermo
> You can also get the dynamic polymorphism without invoking inheritance
> by specifying a protocol that the values in your dict must implement,
> instead. Protocols are plentiful in Python, perhaps more popular than
> type hierarchies.

I'm used to languages with stricter rules than Python. I've read a bit
about Python protocols, but where could I get some more info on
implementation details? Sounds very interesting.

Regards,

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


Re: Checking if a variable is a dictionary

2008-03-09 Thread Guillermo

>A protocol is just an interface that an object agrees to implement. In
>your case, you would state that every object stored in your special
>dict must implement the to_tagged_value method with certain agreeable
>semantics.

Hm... I've searched about the implementation of protocols and now (I
believe) I know how to implement the iterable protocol, for instance,
but have no clue about how to define my own... I'm surely not thinking
the right way, but I don't seem to be able to wrap my head around the
implementation details of "custom" protocols... Is it just a matter of
extending the different object classes (dict, list, tuple...)? Where
do you put the interface/protocol code? :-?

Regards,

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


Re: Checking if a variable is a dictionary

2008-03-09 Thread Guillermo

Mamma mia! My head just exploded. I've seen the light.

So you only need to ·want· to have a protocol? That's amazing... Far
beyond the claim that Python is easy. You define protocols in writing
basically! Even my grandma could have her own Python protocol.

Okay, so I think I know where's the catch now -- you must rely on the
fact that the protocol is implemented, there's no way to enforce it if
you're expecting a parrot-like object. You'd try to call the speak()
method and deal with the error if there's no such method?

Thanks a lot!

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


Python 2.5 + sqlite full text search possible?

2008-10-28 Thread Guillermo

Hi!

Is it possible to load the full-text search module for the SQLite
version bundled with  Python 2.5?

I've tested it and the stand-alone SQLite distribution doesn't seem to
include it (sqlite> .load fts2), nor does Python.

I'm on Windows XP.

Regards,

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


Python 2.5 + sqlite full text search possible?

2008-10-28 Thread Guillermo
Hi!

Is it possible to use the full-text module of SQLite with the sqlite3
module? I've done a bit of investigation and it seems the stand-alone
distribution of SQLite is compiled without it, and so does the version
bundled with Python.

Regards,

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


passing *args "recursively"

2008-05-12 Thread Guillermo

Hi,

This must be very basic, but how'd you pass the same *args several
levels deep?


def func2(*args)

print args # ((1, 2, 3),)
# i want this to output (1, 2, 3) as func1!
# there must be some better way than args[0]?

def func1(*args):

print args # (1, 2, 3)
func2(args)

func1(1,2,3)

Thanks!

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


Keep a script running in the background

2008-06-03 Thread Guillermo

Hi,

I need a script to keep running in the background after it's loaded
some data. It will make this data available to the main program in the
form of a dictionary, but I don't want to reload the calculated data
every time the user needs it via the main program.

I won't be working with an UI, hope that can be made easily in Python
somehow.

Cheers,

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


Re: Keep a script running in the background

2008-06-03 Thread Guillermo

These are the basic requirements:

Script A must keep a dictionary in memory constantly and script B must
be able to access and update this dictionary at any time. Script B
will start and end several times, but script A would ideally keep
running until it's explicitly shut down.

I have the feeling the way to do this is Python is by pickling the
dict, but I need the method that gives the best performance. That's
why I'd rather want to keep it in memory, since I understand pickling
involves reading from and writing to disk.

I'm using SQLite as a database. But this dict is an especial index
that must be accessed at the highest speed possible.
--
http://mail.python.org/mailman/listinfo/python-list


Getting python 2.4 dll

2008-07-28 Thread Guillermo

Hi there,

Is it possible to get a 2.4 dll of python for Windows easily? I need
it to use python as scripting language for Vim.

Regards,

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


Opposite of repr() (kind of)

2008-04-21 Thread Guillermo

Hi there,

How can I turn a string into a callable object/function?

I have a = 'len', and I want to do: if callable(eval(a)): print
"callable", but that doesn't quite work the way I want. :)

Regards,

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


Re: Opposite of repr() (kind of)

2008-04-21 Thread Guillermo

This must be the dumbest question ever...

Solved.

On Apr 21, 1:05 pm, Guillermo <[EMAIL PROTECTED]> wrote:
> Hi there,
>
> How can I turn a string into a callable object/function?
>
> I have a = 'len', and I want to do: if callable(eval(a)): print
> "callable", but that doesn't quite work the way I want. :)
>
> Regards,
>
> Guillermo

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


Uses of docutils

2008-08-31 Thread Guillermo

Hi,

I've been playing with docutils in order to use ReStructedText with
Django, but I was wondering if apart from converting files to html it
adds anything to Python's self-documenting facilities.

For instance, the instructions tell you to run "buildhtml.py .." after
the installation, which generates html files for every txt in the
passed-in directory and subdirectories.

What's so good about having a bunch of html scattered in several
directories? Is there any way in Python to make use of them via the
interpreter? Should one rather copy them to a separate folder for
reference?

Regards,

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


Algorithm used by difflib.get_close_match

2008-09-02 Thread Guillermo

Hi all,

Does anyone know whether this function uses edit distance? If not,
which algorithm is it using?

Regards,

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


virtualenv under Win7: easy_install fails in virtual environments

2009-10-25 Thread Guillermo
Hi,

I've installed setuptools for my default python installation and it
works perfectly without even asking for admin credentials to install
packages.

After that I've installed virtualenv.

If I do:

>>> virtualenv x

... a new virtual environment is created, but whenever I try to run
easy_install within the new virtual environment, I'm prompted to enter
my admin password (I'm running as "Power User" normally) and
easy_install fails complaining that "Can't find D:/correct/path/to/
virtualenv/Scripts/python.exe". This path is private to my normal, non-
admin account.

It also fails if I'm running as an administrator and perform the same
steps.

I've tried runas to no avail too.

Is this a known issue?

Regards,
Guillermo
-- 
http://mail.python.org/mailman/listinfo/python-list


Python unicode and Windows cmd.exe

2010-03-14 Thread Guillermo
Hi,

I would appreciate if someone could point out what am I doing wrong
here.

Basically, I need to save a string containing non-ascii characters to
a file encoded in utf-8.

If I stay in python, everything seems to work fine, but the moment I
try to read the file with another Windows program, everything goes to
hell.

So here's the script unicode2file.py:
===
# encoding=utf-8
import codecs

f = codecs.open("m.txt",mode="w", encoding="utf8")
a = u"mañana"
print repr(a)
f.write(a)
f.close()

f = codecs.open("m.txt", mode="r", encoding="utf8")
a = f.read()
print repr(a)
f.close()
===

That gives the expected output, both calls to repr() yield the same
result.

But now, if I do type me.txt in cmd.exe, I get garbled characters
instead of "ñ".

I then open the file with my editor (Sublime Text), and I see "mañana"
normally. I save (nothing to be saved, really), go back to the dos
prompt, do type m.txt and I get again the same garbled characters.

I then open the file m.txt with notepad, and I see "mañana" normally.
I save (again, no actual modifications), go back to the dos prompt, do
type m.txt and this time it works! I get "mañana". When notepad opens
the file, the encoding is already UTF-8, so short of a UTF-8 bom being
added to the file, I don't know what happens when I save the
unmodified file. Also, I would think that the python script should
save a valid utf-8 file in the first place...

What's going on here?

Regards,
Guillermo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python unicode and Windows cmd.exe

2010-03-14 Thread Guillermo
>    That is what happens: the file now starts with a BOM \xEB\xBB\xBF as
> you can see with a hex editor.

Is this an enforced convention under Windows, then? My head's aching
after so much pulling at my hair, but I have the feeling that the
problem only arises when text travels through the dos console...

Cheers,
Guillermo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python unicode and Windows cmd.exe

2010-03-14 Thread Guillermo
>    The console is commonly using Code Page 437 which is most compatible
> with old DOS programs since it can display line drawing characters. You
> can change the code page to UTF-8 with
> chcp 65001

That's another issue in my actual script. A twofold problem, actually:

1) For me chcp gives 850 and I'm relying on that to decode the bytes I
get back from the console.

I suppose this is bound to fail because another Windows installation
might have a different default codepage.

2) My script gets output from a Popen call (to execute a Powershell
script [new Windows shell language] from Python; it does make sense!).
I suppose changing the Windows codepage for a single Popen call isn't
straightforward/possible?

Right now, I only get the desired result if I decode the output from
Popen as "cp850".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python unicode and Windows cmd.exe

2010-03-14 Thread Guillermo
> 2) My script gets output from a Popen call (to execute a Powershell
> script [new Windows shell language] from Python; it does make sense!).
> I suppose changing the Windows codepage for a single Popen call isn't
> straightforward/possible?

Nevermind. I'm able to change Windows' codepage to 65001 from within
the Powershell script and I get back a string encoded in UTF-8 with
BOM, so problem solved!

Thanks for the help,
Guillermo
-- 
http://mail.python.org/mailman/listinfo/python-list


virtualenvwrapper for Windows (Powershell)

2010-05-09 Thread Guillermo
Hi,

If you've ever missed it on Windows and you can use Powershell, you
might want to take a look at this port of virtualenvwrapper:

http://bitbucket.org/guillermooo/virtualenvwrapper/wiki/Home

It's a work in progress, but is should be fairly functional already.

It requires Powershell v2.

Regards,
Guillermo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: virtualenvwrapper for Windows (Powershell)

2010-05-11 Thread Guillermo
On May 11, 7:43 am, Lawrence D'Oliveiro  wrote:
> In message
> <22cf35af-44d1-43fe-8b90-07f2c6545...@i10g2000yqh.googlegroups.com>,
>
> Guillermo wrote:
> > If you've ever missed it on Windows and you can use Powershell ...
>
> I thought the whole point of Windows was to get away from this command-line
> stuff. Not such a good idea after all?

I suppose it depends.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: virtualenvwrapper for Windows (Powershell)

2010-05-12 Thread Guillermo
On May 12, 4:31 am, Lawrence D'Oliveiro  wrote:
> In message
> <973ca0fa-4a2f-4e3b-91b9-e38917885...@d27g2000yqc.googlegroups.com>,
>
> Guillermo wrote:
> > On May 11, 7:43 am, Lawrence D'Oliveiro 
> > wrote:
>
> >> In message
> >> <22cf35af-44d1-43fe-8b90-07f2c6545...@i10g2000yqh.googlegroups.com>,
>
> >> Guillermo wrote:
>
> >>> If you've ever missed it on Windows and you can use Powershell ...
>
> >> I thought the whole point of Windows was to get away from this
> >> command-line stuff. Not such a good idea after all?
>
> > I suppose it depends.
>
> On the way it’s implemented? Microsoft seems to have botched that as well.

File a bug then. It works here. But I think you're getting a wee bit
off-topic.
-- 
http://mail.python.org/mailman/listinfo/python-list


Hello World!

2007-05-21 Thread Heizenreder Guillermo
Hello World!
I am new in the list

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


getLabel() CD-ROM

2007-08-27 Thread Guillermo Heizenreder
Hi list, I'm new whit pygtk library.

I'm interest to know if there is a class in the graphics library that it
can provide me with information about the CD-ROM label ( something
similar to class KMount in the graphic library pykde[1]).

At the time I'm using pycdio class[2],but i don't wont to my application
by dependent on the above class mentioned.

Thanks and kind regards from Argentina.

P/D: my English it to bad, I'm a novice. 

[1]http://www.riverbankcomputing.com/Docs/PyKDE3/classref/allclasses.html
[2]http://pypi.python.org/pypi/pycdio/0.12




-- 
Heizenreder Guillermo
http://code.google.com/u/gheize/

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


problem with SQLObject + mysql

2007-08-30 Thread Guillermo Heizenreder
Hi list I'm new whit SQLObjet. 
I'm study the tutorial:Connecting databases to Python with SQLObjet[1]

My problem is:
>>>from sqlobject.mysql import builder
>>>con=builder()(user='dbuser',passwd='dbpassword',host='localhost',db='garbanzo')
Traceback (most recent call last):
  File "", line 1, in 
  File
"/usr/lib/python2.5/site-packages/SQLObject-0.9.1-py2.5.egg/sqlobject/mysql/mysqlconnection.py",
 line 51, in __init__
DBAPI.__init__(self, **kw)
  File
"/usr/lib/python2.5/site-packages/SQLObject-0.9.1-py2.5.egg/sqlobject/dbconnection.py",
 line 249, in __init__
DBConnection.__init__(self, **kw)
TypeError: __init__() got an unexpected keyword argument 'passwd'


First i creating the user mysql:
 [EMAIL PROTECTED]:~$ mysql -u root
 mysql> use mysql;
 Database changed
 mysql> create database garbanzo;
 Query OK, 1 row affected (0.02 sec)
 mysql> grant all privileges on garbanzo to 'dbuser'@'localhost'
identified by 'dbpassword';
 Query OK, 0 rows affected (0.10 sec)
 mysql> flush privileges;
 Query OK, 0 rows affected (0.09 sec)


So... how i do to connect?. how create de password correctly? 

Thanks and kind regards from Argentina.
P/D: my English it to bad, I'm a novice, :P.

[1]http://www-128.ibm.com/developerworks/library/os-pythonsqlo/index.html?ca=drs#resources
-- 
Heizenreder Guillermo
http://code.google.com/u/gheize/

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


Re: problem with SQLObject + mysql

2007-08-30 Thread Guillermo Heizenreder
El jue, 30-08-2007 a las 07:33 -0300, Guillermo Heizenreder escribió:
> Hi list I'm new whit SQLObjet. 
> I'm study the tutorial:Connecting databases to Python with SQLObjet[1]
> 
> My problem is:
> >>>from sqlobject.mysql import builder
> >>>con=builder()(user='dbuser',passwd='dbpassword',host='localhost',db='garbanzo')
> Traceback (most recent call last):
>   File "", line 1, in 
>   File
> "/usr/lib/python2.5/site-packages/SQLObject-0.9.1-py2.5.egg/sqlobject/mysql/mysqlconnection.py",
>  line 51, in __init__
> DBAPI.__init__(self, **kw)
>   File
> "/usr/lib/python2.5/site-packages/SQLObject-0.9.1-py2.5.egg/sqlobject/dbconnection.py",
>  line 249, in __init__
> DBConnection.__init__(self, **kw)
> TypeError: __init__() got an unexpected keyword argument 'passwd'

__ini__() got an keyword argument 'password' not 'passwd'

> 
> First i creating the user mysql:
>  [EMAIL PROTECTED]:~$ mysql -u root
>  mysql> use mysql;
>  Database changed
>  mysql> create database garbanzo;
>  Query OK, 1 row affected (0.02 sec)
>  mysql> grant all privileges on garbanzo to 'dbuser'@'localhost'
> identified by 'dbpassword';
>  Query OK, 0 rows affected (0.10 sec)
>  mysql> flush privileges;
>  Query OK, 0 rows affected (0.09 sec)
> 
> 
> So... how i do to connect?. how create de password correctly? 

> Thanks and kind regards from Argentina.
> P/D: my English it to bad, I'm a novice, :P.
> 
> [1]http://www-128.ibm.com/developerworks/library/os-pythonsqlo/index.html?ca=drs#resources

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

[pygtk] problem with TreeView + ListStore

2007-09-04 Thread Guillermo Heizenreder
Hi list
I'm developing a application for learn pygkt, and I need to know when a
user selected or clicked one determinate row of my TreeView for shot
another signal .

Study the tutorial [1] I began to see the explanation that I see in the
chapter 14.7. TreeView Signal and found one in particular
"select-cursor-row", but I don't understood  how implementing.

Something like that.
   if user_selected_row:
  self.hbox_118.show()
  print "YES"   

NOTE: self.hbox_118 = wTree.get_widget("hbox118")

Thank and Regard
  
[1] http://www.pygtk.org/pygtk2tutorial/sec-TreeViewSignals.html

P/D: my English it to bad, I'm a novice.
-- 
Heizenreder Guillermo
http://code.google.com/u/gheize/

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


[python-list] Problem with SQLObject

2007-10-25 Thread Guillermo Heizenreder
I'm creating one aplicattion and I use SQLObject, but I have a little
problem, when I try to create one table my aplicattion crash! :(
Let me show you:

[EMAIL PROTECTED]:~/Proyectos/ghhp/lib$ python
Python 2.4.4 (#2, Apr  5 2007, 20:11:18)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sqlobject import *
>>> from connection import conn
>>> class User(SQLObject):
... _connection = conn
... user_name = StringCol(length=14, unique=True)
... un_pass = StringCol(length=10)
...
>>> User.createTable()
Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib/python2.4/site-packages/sqlobject/main.py", line 1332,
in createTable
conn.createTable(cls)
  File "/usr/lib/python2.4/site-packages/sqlobject/dbconnection.py",
line 528, in createTable
self.query(self.createTableSQL(soClass))
  File "/usr/lib/python2.4/site-packages/sqlobject/dbconnection.py",
line 307, in query
return self._runWithConnection(self._query, s)
  File "/usr/lib/python2.4/site-packages/sqlobject/dbconnection.py",
line 219, in _runWithConnection
conn = self.getConnection()
  File "/usr/lib/python2.4/site-packages/sqlobject/dbconnection.py",
line 230, in getConnection
conn = self.makeConnection()
  File
"/usr/lib/python2.4/site-packages/sqlobject/mysql/mysqlconnection.py",
line 51, in makeConnection
db=self.db, user=self.user, passwd=self.password, **self.kw)
  File "/usr/lib/python2.4/site-packages/MySQLdb/__init__.py", line 75,
in Connect
return Connection(*args, **kwargs)
  File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line
164, in __init__
super(Connection, self).__init__(*args, **kwargs2)
TypeError: an integer is required
>>>

I can't find the mistake. 
First I thought that not create correctly the conection to mysql, but
testening show me this:

>>> User._connection

>>>

Saw it seems that it works.
Please cant you help me.
Thank's and regards

-- 
+-
| Heizenreder Guillermo 
| http://gheize.wordpress.com/
| http://code.google.com/u/gheize/
| http://tipslinux.blogspot.com/
+-

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


Re: [Python-es] Uso de variable Global

2010-12-03 Thread Guillermo Candia Huerta
El 02/12/10 19:04, Pau Cervera escribió:
> Ni idea de Tkinter, pero ¿no puedes almacenar *valor* en una variable de
> instancia de App y convertir la función *muestra* en un método de la classe
> App que teng aceso a las variables de instancia de App?
> 
> -
> Pau
> 
> Python..., what else?
> 
> 
> 2010/12/2 craf 
> 
>> Hola.
>>
>>
>> Estoy probando Tkinter y escribí este pequeño código el cual crea un
>> formulario con un textbox y un botón. Al ingresar un dato en el textbox
>> y presionar el botón, se imprime en la consola el valor.
>>
>>
>> ---CODE
>>
>> from Tkinter import *
>>
>> def muestra():
>>print(valor.get())
>>
>> class App:
>>def __init__(self,master):
>>global valor
>>valor = StringVar()
>>e = Entry(master,textvariable=valor).pack()
>>b = Button(master,text='Mostrar',command=muestra).pack()
>>
>>
>> master = Tk()
>> app = App(master)
>> master.mainloop()
>>
>> -
>>
>> Funciona, pero tuve que hacer uso de una variable Global.
>>
>> Pregunta: ¿Es valida esta forma?, ¿Se puede hacer de otra forma, sin
>> ocuparla?.
>>
>> Saludos.
>>
>> Cristian
>>
>>
>>
>> ___
>> Python-es mailing list
>> [email protected]
>> http://mail.python.org/mailman/listinfo/python-es
>> FAQ: http://python-es-faq.wikidot.com/
>>
> 
puede heredar el botón y agregas los atributos y métodos que necesites,
en el constructor le pasas las variables que necesitas
-- 
http://mail.python.org/mailman/listinfo/python-list