Re: how to get character hex number?

2012-08-31 Thread Peter Otten
Tim Chase wrote:

> On 08/31/12 22:41, contro opinion wrote:
>>> u"english".encode("utf-8")
 'english'
>>> u"english".encode("ascii")
 'english'

 how can i get 656e676c697368 in encode method?
>>>
>>> At least in 2.x, you can do:
>>>
>>>  >>> u"english".encode("hex")
>>>  '656e676c697368'
>>
>> how about in python3.0?
> 
> Well, in 3.1.3 at least, using the u"..." notation dies on me with
> an invalid syntax.  However, as Ian suggests, you can do
> 
>   my_str = "english"
>   "".join("%02x" % c for c in my_str.encode("ascii"))
> 
> or whatever other encoding you want instead of "ascii".

Another option:

>>> binascii.hexlify("english".encode()).decode()
'656e676c697368'


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


Re: why i can't set locale?

2012-08-31 Thread Peter Otten
contro opinion wrote:

 locale.setlocale(locale.LC_ALL, 'gbk')
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python2.6/locale.py", line 513, in setlocale
> return _setlocale(category, locale)
> locale.Error: unsupported locale setting

Try picking one of the locales listed by

$ locale -a

(Goggle suggests that you may be looking for "zh_CN.GBK")

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


Re: to know binary

2012-08-31 Thread Dave Angel
On 09/01/2012 12:59 AM, contro opinion wrote:

1) you top-posted
2) you replied privately, excluding the list from your query

> the file is utf-8 format,
 str='/0x31/0x32/0x33/0x34'

3) No idea what that value is supposed to mean.  Perhaps you intended to
use backslashes here?  And perhaps you meant to omit the zeroes?


> why  unicode(str,"utf-8").encode("utf-8")  can not get  1234?
> 

It gets a string, not an integer.  And the string will be "1234" once
you fix the problems in the earlier line.

While you're at it, you should pick a better name for your string.  str
already has a meaning in Python, and you're hiding that.  No real harm
other than readability, but it'll be embarrassing when you actually need
to use the str() function and you end up trying to call your string.

Still not sure how to interpret your original message.  You said nothing
about unicode, or conversions.

And I've been assuming you're using Python 2.x, but all this will be
different for 3.x

-- 

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


Async client for PostgreSQL?

2012-08-31 Thread Laszlo Nagy
Is there any extension for Python that can do async I/O for PostgreSQL 
with tornadoweb's ioloop?


Something like:

class MainHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
def get(self):

pg_connection.(long_taking_query_sql,params,callback=self.on_query_opened)

def on_query_opened(self, query):
self.write(process_rows(query))
self.finish()



What would be an alternative?

The theoretical problem: suppose there are 100 clients (web browsers) 
connected to the server with keep alive connections. They are doing 
long-polls and they are also sending/receiving events (with short 
response times). Each web browser has an associated state stored on the 
server side, in the memory (as an object tree). The state is bound to 
the client with a session id. Most requests will have to be responded 
with small amounts of data, calculated from the session state, or 
queried from the database. Most database queries are simple, running for 
about 100msec. But a few of them will run for 1sec or more. Number of 
requests ending in database queries is relatively low (10/sec). Other 
requests can be responded must faster.  but they are much more frequent 
(100/sec, that is. 1 request/sec/client).  There is a big global cache 
full of (Python) objects. Their purpose is to reduce the number of 
database queries. These objects in the global cache are emitting events 
to other objects found in the client sessions. Generally, it is not 
possible to tell what request will end in a database query.


Multi-threading is not an option because number of clients is too high 
(running 100 threads is not good). This is why I decided to use anyc 
I/O. Tornadoweb looks good for most requirements: async i/o, store 
session state in objects etc. The biggest problem is that psycopg is not 
compatible with this model. If I use blocking I/O calls inside a request 
handler, then they will block all other requests most of the time, 
resulting in slow response times.


What would be a good solution for this?

Thanks,

   Laszlo

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


Re: Unittest - testing for filenames and filesize

2012-08-31 Thread 88888 Dihedral
On Saturday, September 1, 2012 12:19:10 AM UTC+8, Chris Withers wrote:
> On 23/08/2012 12:25, Tigerstyle wrote:
> 
> > class FileTest(unittest.TestCase):
> 
> >
> 
> >  def setUp(self):
> 
> >  self.origdir = os.getcwd()
> 
> >  self.dirname = tempfile.mkdtemp("testdir")
> 
> >  os.chdir(self.dirname)
> 
> 
> 
> I wouldn't change directories like this, it's pretty fragile, just use 
> 
> absolute paths.
> 
> 
> 
> >  def test_1(self):
> 
> >  "Verify creation of files is possible"
> 
> >  for filename in ("this.txt", "that.txt", "the_other.txt"):
> 
> >  f = open(filename, "w")
> 
> >  f.write("Some text\n")
> 
> >  f.close()
> 
> >  self.assertTrue(f.closed)
> 
> >
> 
> >  def test_2(self):
> 
> >  "Verify that current directory is empty"
> 
> >  self.assertEqual(glob.glob("*"), [], "Directory not empty")
> 
> >
> 
> >  def tearDown(self):
> 
> >  os.chdir(self.origdir)
> 
> >  shutil.rmtree(self.dirname)
> 
> 
> 
> Seeing this, you might find the following tools useful:
> 
> 
> 
> http://packages.python.org/testfixtures/files.html
> 
> 
> 
> cheers,
> 
> 
> 
> Chris
> 
> 
> 
> -- 
> 
> Simplistix - Content Management, Batch Processing & Python Consulting
> 
>  - http://www.simplistix.co.uk

Well, I am thinking  that the directory tree listing services or daemons
supported by the OS by some iterators could be better than the stack
based model.

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


Re: to know binary

2012-08-31 Thread Dave Angel
On 09/01/2012 12:15 AM, contro opinion wrote:
> there is a only line in the file nanmed test:
> 1234
> when i open it whit  xxd
> xxd  test
> what i  get is :
> 000: 3132 3334 0a 1234.
> can you explain it ?
>
>
>

Explain what, exactly?  Explain why you were able to run xxd without
first installing Mumps?

What is it you don't understand?  Do you know hex?  Are you familiar
with the hex codes for common ASCII characters and control characters? 
Does the period at the end of the line bother you?  Are you expecting
some different number of zeroes in the address field?

Since you're apparently running Linux/Unix, you can find xxd executable
by using where xxd.  And you can tell what kind of file it is by running
file on it.  xxd is evidently not written in Python.  So why again are
you asking here?

-- 

DaveA

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


Re: to know binary

2012-08-31 Thread Chris Angelico
On Sat, Sep 1, 2012 at 2:15 PM, contro opinion  wrote:
> there is a only line in the file nanmed test:
> 1234
> when i open it whit  xxd
> xxd  test
> what i  get is :
> 000: 3132 3334 0a 1234.
> can you explain it ?

I would explain it as a file with one line named test:
1234

I would further explain that this uses Unix-style line endings.

Any further explanations will require a much clearer question. Try this:

http://www.catb.org/~esr/faqs/smart-questions.html

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


to know binary

2012-08-31 Thread contro opinion
there is a only line in the file nanmed test:
1234
when i open it whit  xxd
xxd  test
what i  get is :
000: 3132 3334 0a 1234.
can you explain it ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get character hex number?

2012-08-31 Thread Tim Chase
On 08/31/12 22:41, contro opinion wrote:
>> u"english".encode("utf-8")
>>> 'english'
>> u"english".encode("ascii")
>>> 'english'
>>>
>>> how can i get 656e676c697368 in encode method?
>>
>> At least in 2.x, you can do:
>>
>>  >>> u"english".encode("hex")
>>  '656e676c697368'
>
> how about in python3.0?

Well, in 3.1.3 at least, using the u"..." notation dies on me with
an invalid syntax.  However, as Ian suggests, you can do

  my_str = "english"
  "".join("%02x" % c for c in my_str.encode("ascii"))

or whatever other encoding you want instead of "ascii".

-tkc


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


Re: how to get character hex number?

2012-08-31 Thread Tim Chase
On 08/31/12 21:21, contro opinion wrote:
 for i in "english" :
> ...   print(hex((ord(i
> ...
> 0x65
> 0x6e
> 0x67
> 0x6c
> 0x69
> 0x73
> 0x68
 u"english".encode("utf-8")
> 'english'
 u"english".encode("ascii")
> 'english'
> 
> how can i get 656e676c697368 in encode method?

At least in 2.x, you can do:

>>> u"english".encode("hex")
'656e676c697368'

-tkc



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


Re: how to get character hex number?

2012-08-31 Thread Ian Kelly
On Fri, Aug 31, 2012 at 8:21 PM, contro opinion  wrote:
 for i in "english" :
> ...   print(hex((ord(i
> ...
> 0x65
> 0x6e
> 0x67
> 0x6c
> 0x69
> 0x73
> 0x68
 u"english".encode("utf-8")
> 'english'
 u"english".encode("ascii")
> 'english'
>
> how can i get 656e676c697368 in encode method?

>>> ''.join("%02x" % ord(b) for b in u"english".encode("ascii"))
'656e676c697368'
-- 
http://mail.python.org/mailman/listinfo/python-list


how to get character hex number?

2012-08-31 Thread contro opinion
>>> for i in "english" :
...   print(hex((ord(i
...
0x65
0x6e
0x67
0x6c
0x69
0x73
0x68
>>> u"english".encode("utf-8")
'english'
>>> u"english".encode("ascii")
'english'

how can i get 656e676c697368 in encode method?
-- 
http://mail.python.org/mailman/listinfo/python-list


why i can't set locale?

2012-08-31 Thread contro opinion
>>> locale.setlocale(locale.LC_ALL, 'gbk')
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.6/locale.py", line 513, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: thanks!

2012-08-31 Thread Ben Finney
Tim Chase  writes:

> Or we can take the opportunity to thank you for all your work on
> making this a relatively spam-free mailing list. So thanks!

Indeed. This forum has a very high signal-to-noise ratio, largely due to
efforts that are often invisible to the participants.

Thank you!

-- 
 \“The problem with television is that the people must sit and |
  `\keep their eyes glued on a screen: the average American family |
_o__) hasn't time for it.” —_The New York Times_, 1939 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for an IPC solution

2012-08-31 Thread Laszlo Nagy

Zeromq (suggested by someone) is an option since it's pretty fast for
most purposes, but I don't think it uses shared memory.

Interesting question. The documentation says:

http://api.zeromq.org/2-1:zmq-ipc

The inter-process transport is currently only implemented on operating 
systems that provide UNIX domain sockets.


(OFF: Would it be possible to add local IPC support for Windows using 
mmap()? I have seen others doing it.)


At least, it is functional on Windows, and it excels on Linux. I just 
need to make transports configureable. Good enough for me.

The closest
thing I can think of to what you're asking is MPI, intended for
scientific computation.  I don't know of general purpose IPC that uses
it though I've thought it would be interesting.  There are also some
shared memory modules around, including POSH for shared objects, but
they don't switch between memory and sockets AFAIK.

Based on your description, maybe what you really want is Erlang, or
something like it for Python.  There would be more stuff to do than just
supply an IPC library.
Yes, although I would really like to do this job in Python. I'm going to 
make some tests with zeromq. If the speed is good for local 
inter-process communication, then I'll give it a try.


Thanks,

   Laszlo

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


Re: Looking for an IPC solution

2012-08-31 Thread Antoine Pitrou
Laszlo Nagy  shopzeus.com> writes:

> 
> There are just so many IPC modules out there. I'm looking for a solution 
> for developing a new a multi-tier application. The core application will 
> be running on a single computer, so the IPC should be using shared 
> memory (or mmap) and have very short response times. But there will be a 
> tier that will hold application state for clients, and there will be 
> lots of clients. So that tier needs to go to different computers. E.g. 
> the same IPC should also be accessed over TCP/IP. Most messages will be 
> simple data structures, nothing complicated. The ability to run on PyPy 
> would, and also to run on both Windows and Linux would be a plus.

How about the standard multiprocessing module? It supports shared memory, remote
processes, and will most probably work under PyPy:
http://docs.python.org/library/multiprocessing.html

Regards

Antoine.


-- 
Software development and contracting: http://pro.pitrou.net


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


Re: Looking for an IPC solution

2012-08-31 Thread Paul Rubin
Laszlo Nagy  writes:
> application will be running on a single computer, so the IPC should be
> using shared memory (or mmap) and have very short response times.

Zeromq (suggested by someone) is an option since it's pretty fast for
most purposes, but I don't think it uses shared memory.  The closest
thing I can think of to what you're asking is MPI, intended for
scientific computation.  I don't know of general purpose IPC that uses
it though I've thought it would be interesting.  There are also some
shared memory modules around, including POSH for shared objects, but
they don't switch between memory and sockets AFAIK.

Based on your description, maybe what you really want is Erlang, or
something like it for Python.  There would be more stuff to do than just
supply an IPC library.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for an IPC solution

2012-08-31 Thread Marco Nawijn
On Friday, August 31, 2012 9:22:00 PM UTC+2, Laszlo Nagy wrote:
> There are just so many IPC modules out there. I'm looking for a solution 
> 
> for developing a new a multi-tier application. The core application will 
> 
> be running on a single computer, so the IPC should be using shared 
> 
> memory (or mmap) and have very short response times. But there will be a 
> 
> tier that will hold application state for clients, and there will be 
> 
> lots of clients. So that tier needs to go to different computers. E.g. 
> 
> the same IPC should also be accessed over TCP/IP. Most messages will be 
> 
> simple data structures, nothing complicated. The ability to run on PyPy 
> 
> would, and also to run on both Windows and Linux would be a plus.
> 
> 
> 
> I have seen a stand alone cross platform IPC server before that could 
> 
> serve "channels", and send/receive messages using these channels. But I 
> 
> don't remember its name and now I cannot find it. Can somebody please help?
> 
> 
> 
> Thanks,
> 
> 
> 
> Laszlo

Hi,

Are you aware and have you considered zeromq (www.zeromq.org)? It does not 
provide a messaging system, but you could use things like simple strings (json) 
or more complicated things like Protobuf. 

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


Re: [pyxl] xlrd-0.8.0 .xlsx formatting_info=True not implemented

2012-08-31 Thread Albert-Jan Roskam
Hi,

As a work-around, you could use the CRAN R package XLConnect, using RPy or 
RPy2, to do what you want. IIRC it's based on Java, so it's not extremely fast.
http://cran.r-project.org/web/packages/XLConnect/vignettes/XLConnect.pdf
This is another package I just saw for the first time

http://cran.r-project.org/web/packages/xlsx/xlsx.pdf

 
Regards,
Albert-Jan


~~
All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a 
fresh water system, and public health, what have the Romans ever done for us?
~~ 


>
> From: "python-ex...@raf.org" 
>To: python-ex...@googlegroups.com; Python List  
>Sent: Thursday, August 30, 2012 4:57 AM
>Subject: Re: [pyxl] xlrd-0.8.0 .xlsx formatting_info=True not implemented
> 
>John Yeung wrote:
>
>> > is there any other way to tell how many digits excel would round to
>> > when displaying a floating point number? that's my only reason for
>> > needing formatting_info=True.
>> 
>> I have not personally used it, but OpenPyXL is another option for
>> working with .xlsx files, and it might provide the formatting info you
>> need:
>> 
>>  http://packages.python.org/openpyxl/index.html
>>  http://pypi.python.org/pypi/openpyxl/1.5.8
>> 
>> John Y.
>
>thanks but openpyxl doesn't work well enough.
>most of the spreadsheets i need to read contain
>dropdown lists with data validation using a named
>formula like: OFFSET(Data!$K$2,0,0,COUNTA(Data!$K:$K),1)
>which causes openpyxl to throw a NamedRangeException.
>i don't even care about the named objects. i just want
>to know what's in the cell, not what other possible
>values the cell might have had. :-)
>
>apart from that, it does give access to number formats
>so your suggestion would work for simpler spreadsheets.
>
>hopefully the intention that xlrd not support formats in xlsx
>files will change one day into an intention to support them. :-)
>
>until then my users can keep manually saving xlsx files they
>receive as xls before importing them. :-(
>
>maybe i need to investigate some perl modules or pyuno instead.
>perl's Spreadsheet::XSLX module handles formats. it gets the
>date formats a bit wrong but it's workaroundable.
>
>cheers,
>raf
>
>-- 
>You received this message because you are subscribed to the Google Groups 
>"python-excel" group.
>To post to this group, send an email to python-ex...@googlegroups.com.
>To unsubscribe from this group, send email to 
>python-excel+unsubscr...@googlegroups.com.
>For more options, visit this group at 
>http://groups.google.com/group/python-excel?hl=en-GB.
>
>
>
>-- 
http://mail.python.org/mailman/listinfo/python-list


Looking for an IPC solution

2012-08-31 Thread Laszlo Nagy
There are just so many IPC modules out there. I'm looking for a solution 
for developing a new a multi-tier application. The core application will 
be running on a single computer, so the IPC should be using shared 
memory (or mmap) and have very short response times. But there will be a 
tier that will hold application state for clients, and there will be 
lots of clients. So that tier needs to go to different computers. E.g. 
the same IPC should also be accessed over TCP/IP. Most messages will be 
simple data structures, nothing complicated. The ability to run on PyPy 
would, and also to run on both Windows and Linux would be a plus.


I have seen a stand alone cross platform IPC server before that could 
serve "channels", and send/receive messages using these channels. But I 
don't remember its name and now I cannot find it. Can somebody please help?


Thanks,

   Laszlo

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


Re: Tkinter bug in Entry widgets on OS X

2012-08-31 Thread Arnaud Delobelle
On 31 August 2012 16:41, Alister  wrote:
> On Fri, 31 Aug 2012 11:21:14 -0400, Kevin Walzer wrote:
>
>> On 8/31/12 11:18 AM, Arnaud Delobelle wrote:
>>
>>
>>> I'm not trying to do anything.  When a user presses the UP or DOWN
>>> arrow, then a strange character is inserted in the Entry box.  I'd
>>> rather nothing happened.
>>>
>> Why is the user doing that? If they are trying to navigate to a
>> different part of the interface, they need to use the tab key, not the
>> arrow key. It's not a multi-line text widget and shouldn't be expected
>> to work like one.

So you make software that only behaves well when the user does what
they're supposed to do?

> I agree that it is unexpected in a single line entry box but isn't the 1st
> rule of user interface design to assume the user is a moron & will do
> things they are not supposed to do?
>
> Therefore invalid inputs should be handled gracefully (not just insert
> random characters) which is what I think the original poster is
> suggesting.

Indeed.

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


Re: thanks! (was "Test message - please ignore")

2012-08-31 Thread Ethan Furman

Tim Chase wrote:

On 08/31/12 09:15, Skip Montanaro wrote:
We just upgraded the Mailman installation on mail.python.org.  Part of that 
installation includes spam filtering on messages gated from Usenet to the python-
l...@python.org mailing list.  This message is a quick test of that function.  
You can ignore it.


Or we can take the opportunity to thank you for all your work on
making this a relatively spam-free mailing list.  So thanks!


Seconded!  :)

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


Re: Unittest - testing for filenames and filesize

2012-08-31 Thread Chris Withers

On 23/08/2012 12:25, Tigerstyle wrote:

class FileTest(unittest.TestCase):

 def setUp(self):
 self.origdir = os.getcwd()
 self.dirname = tempfile.mkdtemp("testdir")
 os.chdir(self.dirname)


I wouldn't change directories like this, it's pretty fragile, just use 
absolute paths.



 def test_1(self):
 "Verify creation of files is possible"
 for filename in ("this.txt", "that.txt", "the_other.txt"):
 f = open(filename, "w")
 f.write("Some text\n")
 f.close()
 self.assertTrue(f.closed)

 def test_2(self):
 "Verify that current directory is empty"
 self.assertEqual(glob.glob("*"), [], "Directory not empty")

 def tearDown(self):
 os.chdir(self.origdir)
 shutil.rmtree(self.dirname)


Seeing this, you might find the following tools useful:

http://packages.python.org/testfixtures/files.html

cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Basic python extension producing error: "dynamic module not initialized properly"

2012-08-31 Thread Jason Veldicott
Hi,

I am trying to create an extension to call into a c++ library, a library
which simply returns a string, given a string.  At first, a quick and
simple approach was tried (based on post
http://stackoverflow.com/questions/1615813/how-to-use-c-classes-with-ctypes)
in which the usual infrastructure for loading extensions is bypassed.  A
working simple example is shown beneath:

myextension.cpp

#include 

extern "C"
{
int test_func() {
return 10;
}
}

To execute in Python:

from ctypes import cdll
mlib=cdll.LoadLibrary("myextension.dll")
print( mlib.test_func() )

This works fine when function return type is a number, but not when a
string.  C++ code returns char *, which is received by Python as a pointer,
which prints as a number, eg1755066468.  Apparently, based on web posts
viewed, it seems data conversion is required, using a function such
as Py_BuildValue("s", str) from python.h.  But this gave a similar result,
in which a pointer is received by Python instead of a string. The modified
function used in this case:

PyObject * test_func() {
return Py_BuildValue("s", "aString");
}

Resort was then made to the conventional approach of defining a method
table and initializing method.  (Abandoned cdll.LoadLibrary(...) as
subsequently test_func was not recognised, and instead put the dll (.dll
changed to pyd) in /python26/DLLs.)  The revised code:

myextension.cpp

#include 

extern "C"
{
static PyObject * test_func(PyObject *self, PyObject *args)
{
return (PyObject *) 0;
}

static PyMethodDef TestMethods[] = {
{"test",  test_func, METH_VARARGS, "test"},
{NULL, NULL, 0, NULL}
};

PyMODINIT_FUNC initlibTestExtnModule(void) {
(void) Py_InitModule("TestExtnModule", TestMethods);
}
}

Using the import statement "import libTestExtnModule" however produced the
following error message:

"SystemError: dynamic module not initialized properly"

As far as I know there is nothing wrong with the initialisation of the
extension code above.   Perhaps the error is related to compilation.  I
have not used distutils, but rather compiled externally and dropped the dll
(as pyd) into the /DLLs directory as mentioned.  This should work, as far
as I know.  Related to compilation, both MinGW and Python2.6 are 32 bit
versions, and g++ statements used were:

mingw32-g++ "-IC:\\Python26\\include" -O0 -g3 -Wall -c -fmessage-length=0
-o myextension.o "..\\myextension.cpp"
mingw32-g++ -LC:/Python26/libs -shared -o
libTestExtnModule.pyd myextension.o -lpython26

Any suggestions as to why the dynamic module is not initialising properly,
or as to how otherwise a string can be returned, would be greatly
appreciated.

Thanks

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


Re: Tkinter bug in Entry widgets on OS X

2012-08-31 Thread Alister
On Fri, 31 Aug 2012 11:21:14 -0400, Kevin Walzer wrote:

> On 8/31/12 11:18 AM, Arnaud Delobelle wrote:
> 
> 
>> I'm not trying to do anything.  When a user presses the UP or DOWN
>> arrow, then a strange character is inserted in the Entry box.  I'd
>> rather nothing happened.
>>
> Why is the user doing that? If they are trying to navigate to a
> different part of the interface, they need to use the tab key, not the
> arrow key. It's not a multi-line text widget and shouldn't be expected
> to work like one.

I agree that it is unexpected in a single line entry box but isn't the 1st 
rule of user interface design to assume the user is a moron & will do 
things they are not supposed to do? 

Therefore invalid inputs should be handled gracefully (not just insert 
random characters) which is what I think the original poster is 
suggesting.




-- 
Walk softly and carry a megawatt laser.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter bug in Entry widgets on OS X

2012-08-31 Thread Kevin Walzer

On 8/31/12 11:18 AM, Arnaud Delobelle wrote:



I'm not trying to do anything.  When a user presses the UP or DOWN
arrow, then a strange character is inserted in the Entry box.  I'd
rather nothing happened.

Why is the user doing that? If they are trying to navigate to a 
different part of the interface, they need to use the tab key, not the 
arrow key. It's not a multi-line text widget and shouldn't be expected 
to work like one.


--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter bug in Entry widgets on OS X

2012-08-31 Thread Arnaud Delobelle
On 31 August 2012 15:25, Kevin Walzer  wrote:
> On 8/31/12 6:18 AM, Arnaud Delobelle wrote:
>>
>> I'm very inexperienced with Tkinter (I've never used it before).  All
>> I'm looking for is a workaround, i.e. a way to somehow suppress that
>> output.
>
>
> What are you trying to do? Navigate the focus to another widget? You should
> use the tab bar for that, not the arrow key. The entry widget is a
> single-line widget, and doesn't have up/down as the text widget does.

I'm not trying to do anything.  When a user presses the UP or DOWN
arrow, then a strange character is inserted in the Entry box.  I'd
rather nothing happened.

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


Re: Flexible string representation, unicode, typography, ...

2012-08-31 Thread Ian Kelly
On Fri, Aug 31, 2012 at 6:32 AM, Steven D'Aprano
 wrote:
> That's one thing that I'm unclear about -- under what circumstances will
> a string be in compact versus non-compact form?

I understand it to be entirely dependent on which API is used to
construct.  The legacy API generates legacy strings, and the new API
generates compact strings.  From the comments in unicodeobject.h:

/* ASCII-only strings created through PyUnicode_New use the PyASCIIObject
structure. state.ascii and state.compact are set, and the data
immediately follow the structure. utf8_length and wstr_length can be found
in the length field; the utf8 pointer is equal to the data pointer. */

...

Legacy strings are created by PyUnicode_FromUnicode() and
PyUnicode_FromStringAndSize(NULL, size) functions. They become ready
when PyUnicode_READY() is called.

...

/* Non-ASCII strings allocated through PyUnicode_New use the
PyCompactUnicodeObject structure. state.compact is set, and the data
immediately follow the structure. */


Since I'm not sure that this is clear, note that compact vs. legacy
does not describe which character width is used (except that
PyASCIIObject strings are always 1 byte wide).  Legacy and compact
strings can each use the 1, 2, or 4 byte representations.  "Compact"
merely denotes that the character data is stored inline with the
struct (as opposed to being stored somewhere else and pointed at by
the struct), not the relative size of the string data.  Again from the
comments:

Compact strings use only one memory block (structure + characters),
whereas legacy strings use one block for the structure and one block
for characters.

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


Re: Flexible string representation, unicode, typography, ...

2012-08-31 Thread Steven D'Aprano
On Fri, 31 Aug 2012 08:43:55 -0400, Roy Smith wrote:

> In article <503f8e33$0$30001$c3e8da3$54964...@news.astraweb.com>,
>  Steven D'Aprano  wrote:
> 
>> On Thu, 30 Aug 2012 07:02:24 -0400, Roy Smith wrote:
>> > Is the implementation smart enough to know that x == y is always
>> > False if x and y are using different internal representations?
>> 
>> [...] There may be circumstances where two strings have different
>> internal representations even though their content is the same
> 
> If there is a deterministic algorithm which maps string content to
> representation type, then I don't see how it's possible for two strings
> with different representation types to have the same content.  Could you
> give me an example of when this might happen?

There are deterministic algorithms which can result in the same result 
with two different internal formats. Here's an example from Python 2:

py> sum([1, 2**30, -2**30, 2**30, -2**30])
1
py> sum([1, 2**30, 2**30, -2**30, -2**30])
1L

The internal representation (int versus long) differs even though the sum 
is the same.

A second example: the order of keys in a dict is deterministic but 
unpredictable, as it depends on the history of insertions and deletions 
into the dict. So two dicts could be equal, and yet have radically 
different internal layout.

One final example: list resizing. Here are two lists which are equal but 
have different sizes:

py> a = [0]
py> b = range(1)
py> del b[1:]
py> a == b
True
py> sys.getsizeof(a)
36
py> sys.getsizeof(b)
48


Is PEP 393 another example of this? I have no idea. Somebody who is more 
familiar with the details of the implementation would be able to answer 
whether or not that is the case. I'm just suggesting that it is possible.


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


Re: Tkinter bug in Entry widgets on OS X

2012-08-31 Thread Kevin Walzer

On 8/31/12 6:18 AM, Arnaud Delobelle wrote:

I'm very inexperienced with Tkinter (I've never used it before).  All
I'm looking for is a workaround, i.e. a way to somehow suppress that
output.


What are you trying to do? Navigate the focus to another widget? You 
should use the tab bar for that, not the arrow key. The entry widget is 
a single-line widget, and doesn't have up/down as the text widget does.


--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: thanks! (was "Test message - please ignore")

2012-08-31 Thread Tim Chase
On 08/31/12 09:15, Skip Montanaro wrote:
> We just upgraded the Mailman installation on mail.python.org.  Part of that 
> installation includes spam filtering on messages gated from Usenet to the 
> python-
> l...@python.org mailing list.  This message is a quick test of that function. 
>  
> You can ignore it.

Or we can take the opportunity to thank you for all your work on
making this a relatively spam-free mailing list.  So thanks!

-tkc



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


Re: interfacing with x86_64 assembler

2012-08-31 Thread Mark Lawrence

On 31/08/2012 14:58, Grant Edwards wrote:

On 2012-08-31, Mark Lawrence  wrote:

On 31/08/2012 14:40, lipska the kat wrote:



I was hacking away at some x86_64 assembler today
when I found myself obsessively indenting my code
by EXACTLY 4 spaces or (multiples thereof)



What's wrong with structured assembler? :)


Nothing -- it's called "C".




You cannot be Cerious


--
Cheers.

Mark Lawrence.

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


Test message - please ignore

2012-08-31 Thread Skip Montanaro
We just upgraded the Mailman installation on mail.python.org.  Part of that 
installation includes spam filtering on messages gated from Usenet to the 
python-
l...@python.org mailing list.  This message is a quick test of that function.  
You can ignore it.

Skip Montanaro


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


Re: interfacing with x86_64 assembler

2012-08-31 Thread Grant Edwards
On 2012-08-31, Mark Lawrence  wrote:
> On 31/08/2012 14:40, lipska the kat wrote:

>> I was hacking away at some x86_64 assembler today
>> when I found myself obsessively indenting my code
>> by EXACTLY 4 spaces or (multiples thereof)

> What's wrong with structured assembler? :)

Nothing -- it's called "C".

-- 
Grant Edwards   grant.b.edwardsYow! Not SENSUOUS ... only
  at   "FROLICSOME" ... and in
  gmail.comneed of DENTAL WORK ... in
   PAIN!!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: interfacing with x86_64 assembler

2012-08-31 Thread Mark Lawrence

On 31/08/2012 14:40, lipska the kat wrote:

Worryingly

I was hacking away at some x86_64 assembler today
when I found myself obsessively indenting my code
by EXACTLY 4 spaces or (multiples thereof)

Who'd have thought it.

lipska



What's wrong with structured assembler? :)

--
Cheers.

Mark Lawrence.

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


interfacing with x86_64 assembler

2012-08-31 Thread lipska the kat

Worryingly

I was hacking away at some x86_64 assembler today
when I found myself obsessively indenting my code
by EXACTLY 4 spaces or (multiples thereof)

Who'd have thought it.

lipska

--
Lipska the Kat©: Troll hunter, sandbox destroyer
and farscape dreamer of Aeryn Sun
--
http://mail.python.org/mailman/listinfo/python-list


Re: Flexible string representation, unicode, typography, ...

2012-08-31 Thread Roy Smith
In article <503f8e33$0$30001$c3e8da3$54964...@news.astraweb.com>,
 Steven D'Aprano  wrote:

> On Thu, 30 Aug 2012 07:02:24 -0400, Roy Smith wrote:
> > Is the implementation smart enough to know that x == y is always False
> > if x and y are using different internal representations?
> 
> [...] There may be circumstances where two strings have different 
> internal representations even though their content is the same

If there is a deterministic algorithm which maps string content to 
representation type, then I don't see how it's possible for two strings 
with different representation types to have the same content.  Could you 
give me an example of when this might happen?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Flexible string representation, unicode, typography, ...

2012-08-31 Thread Steven D'Aprano
On Thu, 30 Aug 2012 16:44:32 -0400, Terry Reedy wrote:

> On 8/30/2012 12:00 PM, Steven D'Aprano wrote:
>> On Thu, 30 Aug 2012 07:02:24 -0400, Roy Smith wrote:
[...]
>>> Is the implementation smart enough to know that x == y is always False
>>> if x and y are using different internal representations?
> 
> Yes, after checking lengths, and in same circumstances, x != y is True.
[snip C code]

Thanks Terry for looking that up.

> 'a in s' is also False if a chars are wider than s chars.

Now that's a nice optimization!

[...]
>> But x and y are not necessarily always False just because they have
>> different representations. There may be circumstances where two strings
>> have different internal representations even though their content is
>> the same, so it's an unsafe optimization to automatically treat them as
>> unequal.
> 
> I am sure that str objects are always in canonical form once visible to
> Python code. Note that unready (non-canonical) objects are rejected by
> the rich comparison function.

That's one thing that I'm unclear about -- under what circumstances will 
a string be in compact versus non-compact form? Reading between the 
lines, I guess that a lot of the complexity of the implementation only 
occurs while a string is being built. E.g. if you have Python code like 
this:

''.join(str(x) for x in something)  # a generator expression

Python can't tell how much space to allocate for the string -- it doesn't 
know either the overall length of the string or the width of the 
characters. So I presume that there is string builder code for dealing 
with that, and that it involves resizing blocks of memory.

But if you do this:

''.join([str(x) for x in something])  # a list comprehension

Python could scan the list first, find out the widest char, and allocate 
exactly the amount of space needed for the string. Even in Python 2, 
joining a list comp is much faster than joining a gen expression.



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


Re: XML parser: Element ordering?

2012-08-31 Thread Dave Angel
On 08/31/2012 08:21 AM, Stefan Behnel wrote:
> Florian Lindner, 31.08.2012 14:03:
>> I plan to use the etree.ElementTree XML parser to parse a config file
>> in which the order of the elements matter, e.g.:
>>
>> 
>> 
>> 
>>
>> is not equal to:
>>
>> 
>> 
>> 
>>
>> I have found different answers to the question if order matters in XML
>> documents. So my question here: Does it matters (and is more or less
>> guarenteed to matter in the future) for the ElementTree parser of
>> python?
> It matters for XML documents, so, yes, any XML parser will definitely
> honour the document order (which is actually well defined for an XML 
> document).
>
> What you might be referring to is the case of a specific XML document
> format, where the application (or sometimes specification) can explicitly
> state that the element order in a given subtree has no meaning for the
> semantics of the element and that therefore code must ignore the order in
> which elements occur. But that won't magically make the parser ignore it
> for you. That's a totally different level of abstraction and a deliberate
> decision of the code that *uses* the parser.
>
>
There is a place in xml documents which is defined to be unordered. 
That's the attributes within one element.



is indistinguishable from:



-- 

DaveA

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


Re: XML parser: Element ordering?

2012-08-31 Thread Stefan Behnel
Florian Lindner, 31.08.2012 14:03:
> I plan to use the etree.ElementTree XML parser to parse a config file
> in which the order of the elements matter, e.g.:
> 
> 
> 
> 
> 
> is not equal to:
> 
> 
> 
> 
> 
> I have found different answers to the question if order matters in XML
> documents. So my question here: Does it matters (and is more or less
> guarenteed to matter in the future) for the ElementTree parser of
> python?

It matters for XML documents, so, yes, any XML parser will definitely
honour the document order (which is actually well defined for an XML document).

What you might be referring to is the case of a specific XML document
format, where the application (or sometimes specification) can explicitly
state that the element order in a given subtree has no meaning for the
semantics of the element and that therefore code must ignore the order in
which elements occur. But that won't magically make the parser ignore it
for you. That's a totally different level of abstraction and a deliberate
decision of the code that *uses* the parser.

Stefan


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


XML parser: Element ordering?

2012-08-31 Thread Florian Lindner
Hello,

I plan to use the etree.ElementTree XML parser to parse a config file
in which the order of the elements matter, e.g.:





is not equal to:





I have found different answers to the question if order matters in XML
documents. So my question here: Does it matters (and is more or less
guarenteed to matter in the future) for the ElementTree parser of
python?

Thanks,

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


Re: Context manager to save/restore a name binding

2012-08-31 Thread Chris Withers

Hi Ben,

On 31/08/2012 03:36, Ben Finney wrote:

That way, I can set ‘sys.dont_write_bytecode’ to the value I need in
this part of the code, knowing that however the code continues the
previous value of that setting will be restored to whatever it was
before I touched it.

Have I re-invented a context manager which already exists? Is there a
better way to do what ‘preserve_value’ is doing?


Depends on the context (ho ho..), but if it's testing, then have a look at:

http://packages.python.org/testfixtures/mocking.html#the-context-manager

There's plenty of other goodies you may like in there too...

cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Tkinter bug in Entry widgets on OS X

2012-08-31 Thread Arnaud Delobelle
Hi all,

I'm writing a small GUI on OS X (v. 10.7.4) using Tkinter.  I'm using
stock Python.  It mostly works fine but there is a bug in Entry
widgets: if and Entry widget has focus and I press the UP arrow, a
"\uf700" gets inserted in the widget.  If I press the DOWN arrow, a
"\uf701" gets inserted.

I'm very inexperienced with Tkinter (I've never used it before).  All
I'm looking for is a workaround, i.e. a way to somehow suppress that
output.

Thanks in advance,

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


Re: Context manager to save/restore a name binding

2012-08-31 Thread Ben Finney
Peter Otten <__pete...@web.de> writes:

> You should wrap yield in a try ... finally. You might allow setting
> the new value in the manager (untested):

Thank you, both good advice.

I would still like to know if Python already has something to make this
unnecessary.

-- 
 \  “Compulsory unification of opinion achieves only the unanimity |
  `\of the graveyard.” —Justice Roberts in 319 U.S. 624 (1943) |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Call perl to store data in DB

2012-08-31 Thread Mulla
On Friday, August 31, 2012 2:49:32 PM UTC+5:30, Octavian Rasnita wrote:
> Maybe I didn't understand well, but if you want your Perl program to get and 
> store the data submitted by the form, then the action of the form should 
> point to the Perl script something like:
> 
> 
> 
> 
> 
> 
> 
> So your "form" object in Python should set the action as the path to the Perl 
> program.
> 
> 
> 
> --
> Octavian
> 
> 
> - Original Message - 
> 
> From: "Mulla" 
> 
> Newsgroups: comp.lang.python
> 
> To: 
> 
> Sent: Friday, August 31, 2012 11:40 AM
> 
> Subject: Call perl to store data in DB
> 
> 
> 
> 
> 
> > hey,
> 
> > 
> 
> > when i submit the form in html , the entered data 
> > (fname,lanme,uname.)all have to come in perl script to store that data 
> > in DB.
> 
> > 
> 
> > 
> 
> > Python View.py
> 
> > 
> 
> > 
> 
> > def ProfileRegistration(request):
> 
> >if request.user.is_authenticated():
> 
> >return HttpResponseRedirect('/profile/')
> 
> >if request.method == 'POST':
> 
> >form = RegistrationForm(data=request.POST, files=request.FILES)
> 
> >if form.is_bound and form.is_valid():
> 
> >user = 
> > User.objects.create_user(username=form.cleaned_data['username'],
> 
> >email=form.cleaned_data['email'],
> 
> >
> > password=form.cleaned_data['password'],)
> 
> >new_user= user.save()
> 
> >profile = 
> > Profile(user=user,firstname=form.cleaned_data['firstname'],
> 
> >  lastname=form.cleaned_data['lastname'],
> 
> >  telephone=form.cleaned_data['telephone'],
> 
> >  service=form.cleaned_data['service'],
> 
> >  servicetype=form.cleaned_data['servicetype'],)
> 
> >new_user = profile.save()
> 
> >   # messages.info(request, "Thank you for registration.Please login 
> > to continue")
> 
> >   # login(request, new_user)
> 
> >return HttpResponseRedirect('/dashboard/')
> 
> >else:
> 
> >return render_to_response('register.html',{'form': 
> > form},context_instance=RequestContext(request))
> 
> >else:
> 
> >form = RegistrationForm()
> 
> >context = {'form':form}
> 
> >return render_to_response('register.html',context, 
> > context_instance=RequestContext(request))
> 
> > 
> 
> > Below in my perl script 
> 
> > 
> 
> > 
> 
> > #!/usr/bin/perl
> 
> > 
> 
> > use strict;
> 
> > use warnings;
> 
> > use user;
> 
> > 
> 
> > 
> 
> > 
> 
> > my $tempuser = new user ();
> 
> > 
> 
> > if ($tempuser->readbyfirstname('Pervez') eq 1) {
> 
> > # Continue processing since we found a match
> 
> > if($tempuser->{lastname} eq 'Noel')
> 
> >{
> 
> >print "Name already exists, \n";
> 
> >}
> 
> > }
> 
> > 
> 
> > my $tempuser1 = new user();
> 
> > $tempuser1->readbyemail_id('mullaper...@gmail.com'); 
> 
> >if($tempuser1->{email_id} eq 'mullaper...@gmail.com')
> 
> >{
> 
> >print "email_id is in use \n";
> 
> >}
> 
> >
> 
> > 
> 
> > 
> 
> > my $tempuser2 = new user();
> 
> > $tempuser2->readbyusername('Tim_sir');
> 
> >if ($tempuser2->{username} eq 'Mulla') 
> 
> >{
> 
> >print "username is already present\n";
> 
> >}
> 
> > else {
> 
> > print "we have no match\n";
> 
> > }
> 
> > 
> 
> >my $tempuser4 = new user('pervez', '', 'mulla', 'mullaper...@gmail.com', 
> > '193274198');
> 
> >my $string = $tempuser4->{firstname};
> 
> >my @c = split(//, $string);
> 
> >my $userhash = "00$c[0]$c[-1]";
> 
> >print "$userhash \n";
> 
> >#$tempuser4->{userhash} = $userhash;
> 
> >$tempuser4->setuserhash( "$userhash" );
> 
> >$tempuser4->write;
> 
> >
> 
> > 
> 
> > when I submit data , that data must come in place "my $tempuser4 = new 
> > user('pervez', '', 'mulla', 'mullaper...@gmail.com', '193274198');" ...
> 
> > 
> 
> > how can I do this ...>>?
> 
> > 
> 
> > Look forward for hear from you soon
> 
> > 
> 
> > Thank You
> 
> > -- 
> 
> > http://mail.python.org/mailman/listinfo/python-list
Thank You Octavian
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Call perl to store data in DB

2012-08-31 Thread Octavian Rasnita
Maybe I didn't understand well, but if you want your Perl program to get and 
store the data submitted by the form, then the action of the form should point 
to the Perl script something like:



So your "form" object in Python should set the action as the path to the Perl 
program.

--Octavian

- Original Message - 
From: "Mulla" 
Newsgroups: comp.lang.python
To: 
Sent: Friday, August 31, 2012 11:40 AM
Subject: Call perl to store data in DB


> hey,
> 
> when i submit the form in html , the entered data (fname,lanme,uname.)all 
> have to come in perl script to store that data in DB.
> 
> 
> Python View.py
> 
> 
> def ProfileRegistration(request):
>if request.user.is_authenticated():
>return HttpResponseRedirect('/profile/')
>if request.method == 'POST':
>form = RegistrationForm(data=request.POST, files=request.FILES)
>if form.is_bound and form.is_valid():
>user = 
> User.objects.create_user(username=form.cleaned_data['username'],
>email=form.cleaned_data['email'],
>
> password=form.cleaned_data['password'],)
>new_user= user.save()
>profile = 
> Profile(user=user,firstname=form.cleaned_data['firstname'],
>  lastname=form.cleaned_data['lastname'],
>  telephone=form.cleaned_data['telephone'],
>  service=form.cleaned_data['service'],
>  servicetype=form.cleaned_data['servicetype'],)
>new_user = profile.save()
>   # messages.info(request, "Thank you for registration.Please login 
> to continue")
>   # login(request, new_user)
>return HttpResponseRedirect('/dashboard/')
>else:
>return render_to_response('register.html',{'form': 
> form},context_instance=RequestContext(request))
>else:
>form = RegistrationForm()
>context = {'form':form}
>return render_to_response('register.html',context, 
> context_instance=RequestContext(request))
> 
> Below in my perl script 
> 
> 
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> use user;
> 
> 
> 
> my $tempuser = new user ();
> 
> if ($tempuser->readbyfirstname('Pervez') eq 1) {
> # Continue processing since we found a match
> if($tempuser->{lastname} eq 'Noel')
>{
>print "Name already exists, \n";
>}
> }
> 
> my $tempuser1 = new user();
> $tempuser1->readbyemail_id('mullaper...@gmail.com'); 
>if($tempuser1->{email_id} eq 'mullaper...@gmail.com')
>{
>print "email_id is in use \n";
>}
>
> 
> 
> my $tempuser2 = new user();
> $tempuser2->readbyusername('Tim_sir');
>if ($tempuser2->{username} eq 'Mulla') 
>{
>print "username is already present\n";
>}
> else {
> print "we have no match\n";
> }
> 
>my $tempuser4 = new user('pervez', '', 'mulla', 'mullaper...@gmail.com', 
> '193274198');
>my $string = $tempuser4->{firstname};
>my @c = split(//, $string);
>my $userhash = "00$c[0]$c[-1]";
>print "$userhash \n";
>#$tempuser4->{userhash} = $userhash;
>$tempuser4->setuserhash( "$userhash" );
>$tempuser4->write;
>
> 
> when I submit data , that data must come in place "my $tempuser4 = new 
> user('pervez', '', 'mulla', 'mullaper...@gmail.com', '193274198');" ...
> 
> how can I do this ...>>?
> 
> Look forward for hear from you soon
> 
> Thank You
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Call perl to store data in DB

2012-08-31 Thread Mark Lawrence

On 31/08/2012 09:40, Mulla wrote:

[snip]


how can I do this ...>>?

Look forward for hear from you soon

Thank You



Search the archives as it's the fourth time the question has been asked 
within a few weeks.


--
Cheers.

Mark Lawrence.

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


Call perl to store data in DB

2012-08-31 Thread Mulla
hey,

when i submit the form in html , the entered data (fname,lanme,uname.)all 
have to come in perl script to store that data in DB.


Python View.py


def ProfileRegistration(request):
if request.user.is_authenticated():
return HttpResponseRedirect('/profile/')
if request.method == 'POST':
form = RegistrationForm(data=request.POST, files=request.FILES)
if form.is_bound and form.is_valid():
user = 
User.objects.create_user(username=form.cleaned_data['username'],
email=form.cleaned_data['email'],

password=form.cleaned_data['password'],)
new_user= user.save()
profile = 
Profile(user=user,firstname=form.cleaned_data['firstname'],
  lastname=form.cleaned_data['lastname'],
  telephone=form.cleaned_data['telephone'],
  service=form.cleaned_data['service'],
  servicetype=form.cleaned_data['servicetype'],)
new_user = profile.save()
   # messages.info(request, "Thank you for registration.Please login to 
continue")
   # login(request, new_user)
return HttpResponseRedirect('/dashboard/')
else:
return render_to_response('register.html',{'form': 
form},context_instance=RequestContext(request))
else:
form = RegistrationForm()
context = {'form':form}
return render_to_response('register.html',context, 
context_instance=RequestContext(request))

Below in my perl script 


#!/usr/bin/perl

use strict;
use warnings;
use user;



my $tempuser = new user ();

if ($tempuser->readbyfirstname('Pervez') eq 1) {
# Continue processing since we found a match
 if($tempuser->{lastname} eq 'Noel')
{
print "Name already exists, \n";
}
}

my $tempuser1 = new user();
$tempuser1->readbyemail_id('mullaper...@gmail.com'); 
if($tempuser1->{email_id} eq 'mullaper...@gmail.com')
{
print "email_id is in use \n";
}



my $tempuser2 = new user();
$tempuser2->readbyusername('Tim_sir');
if ($tempuser2->{username} eq 'Mulla') 
{
print "username is already present\n";
}
else {
print "we have no match\n";
}

my $tempuser4 = new user('pervez', '', 'mulla', 'mullaper...@gmail.com', 
'193274198');
my $string = $tempuser4->{firstname};
my @c = split(//, $string);
my $userhash = "00$c[0]$c[-1]";
print "$userhash \n";
#$tempuser4->{userhash} = $userhash;
$tempuser4->setuserhash( "$userhash" );
$tempuser4->write;

 
when I submit data , that data must come in place "my $tempuser4 = new 
user('pervez', '', 'mulla', 'mullaper...@gmail.com', '193274198');" ...

how can I do this ...>>?

Look forward for hear from you soon

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