Re: Where are documentation for Gnome

2012-10-15 Thread Matěj Cepl
On Sat, 13 Oct 2012 20:14:50 +0200, Kwpolska wrote:
> https://live.gnome.org/EyeOfGnome/Plugins#Python
> 
> That is all the documentation in existence for Python plugins.
> 
> Examples:
> http://git.gnome.org/browse/eog-plugins/tree/plugins/slideshowshuffle
> http://git.gnome.org/browse/eog-plugins/tree/plugins/pythonconsole
> 
> The C code may be of use:
> 
> http://ftp.acc.umu.se/pub/GNOME/sources/eog/3.6/eog-3.6.0.tar.xz
> 
> Have fun— oh wait.  You can’t, because PyGTK is an unreadable mess.
> And you are working with undocumented stuff.

Also, it is irrelevant ... Gnome3 doesn't use PyGTK, you want PyGIO (for 
example https://live.gnome.org/PyGObject/IntrospectionPorting and other 
links to PyGIO). Hint: if you install gobject-introsepction-devel (or 
whatever is the name of the package in your distro), you will get in 
devhelp quite a nice documentation, and also a lot of stuff to read in /
usr/share/gir-*/.

Best,

Matěj

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


Re: delete xml elements - using xpath search

2012-10-15 Thread Stefan Behnel
Tharanga Abeyseela, 16.10.2012 05:57:
> i need to delete the following pattern and its parent node from my xml
> file (IF THE SEARCH STRING FOUND)
> 
> NC
> 
> if i find the above particular string , i need to delete the XML
> elements (parent of the  element.  problem is i have different
> parent nodes with different names..
> 
> like
> 
> 
>   xxx
>   xxx 
>   NC
> 
> 
> 
>  
>  xxx 
>  NC
> 
> 
> 
> xxx 
>  xxx 
>  M
> 
> 
> 
> as an example, i need to remove  section and  section
> from my xml, (because it has the word NC) but need to keep 
> 
> can someone point me to the correct direction, or code snippet

Use the xml.etree.ElementTree module. Just parse() in the file, iterate
over the nodes, use the findtext() method to search for the text of
"Rating" tags and compare it to "NC". Keep the nodes that don't match.

Stefan


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


Re: Which book is the best?

2012-10-15 Thread Dwight Hutto
On Tue, Oct 16, 2012 at 12:27 AM, 老爷  wrote:
> I have strong c++ development experience.  But now I want to study the
> python to do some windows setting task, such as editing file, changing the
> system setting, doing some network processing.  Please help me which book is
> the best?
>
>
Definitely command line apps/command line usage.

 I could recommend google searches, but use the calls to the OS, and
you can accomplish a good bit of things.


-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT Questions

2012-10-15 Thread Dwight Hutto
On Tue, Oct 16, 2012 at 12:05 AM, Dwight Hutto  wrote:
> Like a lot of people here, I'm trying to build a web development business.
> I'm starting off by building a profile on a freelance site.
>
> I would like some honest opinions(don't be too harsh, or you can be, that's 
> what it's about), about my approach.
> I'm looking for a team effort to analyze my marketability.
>
> This is just my prototype freelance portfolio:
>
> https://www.odesk.com/users/~01710ac049863018eb
>
> --
> Best Regards,
> David Hutto
> CEO: http://www.hitwebdevelopment.com



-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to insert random error in a programming

2012-10-15 Thread Steven D'Aprano
On Mon, 15 Oct 2012 18:21:55 -0700, alex23 wrote:

> On Oct 16, 5:52 am, Chris Angelico  wrote:
>> Surely there's a shorter way to rot13 a piece of text? CODE GOLF!
> 
> In Python2: "a piece of string".encode('rot13') :)

And in Python 3, unfortunately there has been a right-royal mess made of 
the codecs system:

http://bugs.python.org/issue7475

So I expect that in Python 3.4 this will work:

"a piece of string".transform('rot13')

or this:

import codecs
codecs.encode('a piece of string', 'rot13')


but who knows really?



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


Is there a way to create kernel log messages via Python?

2012-10-15 Thread J
Hi...

I have a bit of code that does the following:

uses the syslog module to inject a LOG_INFO message into the syslog on
my linux machine
runs a suspend/resume cycle
uses the syslog module to inkect a LOG_INFO message marking the end of test.

Then I parse everything between the start and stop markers for certain
items that the Linux kernel logs during a suspend and resume cycle.

But my  "resume complete" timing is not as accurate as it could be.
The problem with doing it this way is that while I can find definite
kernel messages that mark various points in the suspend/resume cycle,
the final message when the kernel is done resuming is NOT the point I
actually want to mark.

Instead, the end point I want is the time of the ending marker itself,
as this happens after certain other things are done such as resumption
of networking services.

Here's the problem.  I can't just use syslog timestamps.  The reason
is that the syslog timestamps are only indicative of when messages are
written to syslog via syslogd.  The kernel timestamps are different.
For example, the following bits of log are taken from the time the
test starts until the end of the "going to sleep" kernel messages.
First, note that there's a 5 second difference between the START
marker and the first kernel message.  Next, look at the kernel
timestamps.  The total real time to suspend starts at 421320.380947
and ends at 421322.386355, around 2 seconds later, where the log
messages themselves all state that the events occurred at the same
time.

Oct 15 10:24:19 klaatu sleep_test: ---SLEEP TEST START 1350296656---
Oct 15 10:25:24 klaatu kernel: [421320.380947] PM: Syncing filesystems ... done.
Oct 15 10:25:24 klaatu kernel: [421320.391282] PM: Preparing system
for mem sleep
[SNIP]
Oct 15 10:25:24 klaatu kernel: [421322.282943] Broke affinity for irq 23
Oct 15 10:25:24 klaatu kernel: [421322.386355] CPU 7 is now offline

So, what I REALLY want is to inject my start/stop markers into klogd
rather than syslogd.  This will, I hope, give my markers kernel
timestamps rather than syslog timestamps which are not as accurate.

So does anyone know of a way to do this?  Unfortunately, I've tried
some searching but google doesn't like the term klog, and most of the
hits involved injecting code or other things that are not related at
all.

Or, if there's a better way to get accurate timestamps, what would that be?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: LinkedIn Python group discussions

2012-10-15 Thread Dwight Hutto
On Sun, Oct 14, 2012 at 7:42 AM, Mark Lawrence  wrote:
> I've been sparked into raising the subject as this has just come up "Does
> Jython/Python fall short of true POSIX thread parallelism?".  I'm not
> qualified to comment and I recognise relatively few names amongst the people
> who do participate over there.

I subscribe to many lists, but you're not going to find people
interested in certain aspects of programming.


The last thing I'd want would be FUD or
> worse still complete crap being written in response to any thread and me not
> being in a position to reply.

If you're on the right mailing list, and you can use google for a
little research, then it's very unlikely you'll get bs'd

 Is this something for the Python community
> here to be thinking about?

Not really. These are specific things being questioned that might have
something to do with python, but are mainly specific to certain areas
of computing that involve python, but need to be solved by others in
other areas of computing/utilization of python.

Sometimes it's their problem, but sometimes it's pythons, which does
need to be analyzed and corrected for specific systems/OS's.


-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


easy_install says "not a recognized archive type" Windows Py3

2012-10-15 Thread Noah Coad
Hello, I'm new to Python, have v3.0 32bit installed on Windows 7, installed 
distribute, now trying to install pymysql and am getting the below error.  Any 
pointers on how to fix?  thanks!!  -Noah

[C:\Python32]pip install --upgrade distribute
Real name of requirement distribute is distribute
Requirement already up-to-date: distribute in c:\python32\lib\site-packages\dist
ribute-0.6.28-py3.2.egg
Cleaning up...

[C:\Python32]easy_install pymysql
Searching for pymysql
Reading http://pypi.python.org/simple/pymysql/
Couldn't find index page for 'pymysql' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
Reading http://pypi.python.org/simple/PyMySQL/
Reading http://code.google.com/p/pymysql
Best match: PyMySQL 0.5
Downloading http://pypi.python.org/packages/source/P/PyMySQL/PyMySQL-0.5.tar.gz#
md5=125e8a3449e05afcb04874a19673426b
Processing PyMySQL-0.5.tar.gz
error: Not a recognized archive type: c:\users\noahco~1\appdata\local\temp\easy_
install-gpekqc\PyMySQL-0.5.tar.gz
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to insert random error in a programming

2012-10-15 Thread Roy Smith
In article 
,
 rusi  wrote:

> On Oct 15, 9:00 pm, John Gordon  wrote:
> > In  Debashish Saha 
> >  writes:
> >
> > > how to insert random error in a programming?
> >
> > Open the program source file and replace the Nth character with a random
> > character.
> 
> I'm reminded of a description of vi:
> 
> A program with two modes, one in which it beeps and the other in which
> it corrupts your file.

All the vi you need to know:   : q ! 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to insert random error in a programming

2012-10-15 Thread rusi
On Oct 15, 9:00 pm, John Gordon  wrote:
> In  Debashish Saha 
>  writes:
>
> > how to insert random error in a programming?
>
> Open the program source file and replace the Nth character with a random
> character.

I'm reminded of a description of vi:

A program with two modes, one in which it beeps and the other in which
it corrupts your file.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fastest web framework

2012-10-15 Thread alex23
On Oct 15, 11:40 pm, Andriy Kornatskyy 
wrote:
> Comments or suggestions are welcome.

Performance speed is possibly the least interesting aspect of web
frameworks; ease of use & readily re-usable 3rd party code figures
much higher, IMO. Rather than constantly hammer on about performance,
maybe you could take the time to explain any other advantages your
framework provides.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to insert random error in a programming

2012-10-15 Thread alex23
On Oct 16, 5:52 am, Chris Angelico  wrote:
> Surely there's a shorter way to rot13 a piece of text? CODE GOLF!

In Python2: "a piece of string".encode('rot13') :)

> At very least, a single cryptic expression in place of your nice clear
> loops MUST be an improvement.
>
> d = dict((chr(i+c),chr((i+13)%26+c))for i in range(26)for c in(65,97))

Do I get points for explicitness?

import string as s
print "a piece of text".translate(
s.maketrans(
s.letters,
s.letters[:26][13:]+s.letters[:26][:13]+s.letters[26:]
[13:]+s.letters[26:][:13]
)
)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exception Messages

2012-10-15 Thread Steven D'Aprano
On Mon, 15 Oct 2012 09:00:15 -0700, Wanderer wrote:

> How do you get Exceptions to print messages? I have an exception defined
> like this
> 
> class PvCamError(Exception):
> def __init__(self, msg):
> self.msg = msg

Please don't invent yet another interface for exception messages. 
Exceptions already have two defined interfaces for accessing the error 
message:

exception.message  # older, now obsolete, and gone in Python 3.
exception.args  # recommended way

Please use the same interface that nearly all exceptions already have and 
use an "args" argument. The easiest way to do this is also the simplest:

class PvCamError(Exception): pass


If you *must* support "msg", do something like this:

class PvCamError(Exception):
def __init__(self, msg, *args):
super(PvCamError, self).__init__(msg, *args)  # see footnote [1]
self.msg = msg





[1] If you're using Python 3, you can abbreviate the super call to:

super().__init__(self, msg, *args)



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


Re: how to insert random error in a programming

2012-10-15 Thread Steven D'Aprano
On Mon, 15 Oct 2012 19:25:38 +0530, Debashish Saha wrote:

> how to insert random error in a programming?

While editing the source code, have your cat walk across the keyboard.

I really think you need to explain your question better.



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


Using pipe_controller to swap pipe components at runtime

2012-10-15 Thread vasudevram

I added a couple of methods / functions to my pipe_controller Python module, 
the Python tool to experiment with pipelined functions within a program.

With these additions, it is now possible to swap the components of a 
pipe_controller 'pipe' programmatically, at runtime (*), and then run the pipe 
again (all within the same program), with differing results (from before and 
after the swap).

(*) Instead of having to edit the source code to change the order in which the 
functions in the pipe are called, that change of order can be done 
programmatically, via a swap_processors() method.

Blog post about it:

http://jugad2.blogspot.in/2012/10/swapping-pipe-components-at-runtime.html

The post includes snippets of the added methods / functions, and a sample run 
of a test program that demonstrates the new component-swapping feature.

The latest code with the above changes is on Bitbucket at:

https://bitbucket.org/vasudevram/pipe_controller

- Vasudev Ram
www.dancingbison.com
jugad2.blogspot.com

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


Re: how to insert random error in a programming

2012-10-15 Thread Joshua Landau
On 15 October 2012 20:51, Chris Angelico  wrote:

> On Tue, Oct 16, 2012 at 6:28 AM, Mark Lawrence 
> wrote:
> > I like clearly written code like this
> >
> > "
> > d = {}
> > for c in (65, 97):
> > for i in range(26):
> > d[chr(i+c)] = chr((i+13) % 26 + c)
> >
> > print "".join([d.get(c, c) for c in s])
>
> Surely there's a shorter way to rot13 a piece of text? CODE GOLF!
>
> At very least, a single cryptic expression in place of your nice clear
> loops MUST be an improvement.
>
> d = dict((chr(i+c),chr((i+13)%26+c))for i in range(26)for c in(65,97))
>
> And with superfluous spaces removed like that, it takes 0.02
> jiggawatts less power in DeLorean Python.
>



> print("".join(chr([[ł,(ł+21)%26+96],[ł%26+65]][64<ł<91][96<ł<123])for ł in
> map(ord,s)))


That was fun. Remember, Unicode has more characters, so you can fit more
code in less space.

<*Oh God, what have I done?!>*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numpy - 2D matrix/array - initialization like in Matlab...

2012-10-15 Thread someone

On 10/15/2012 11:26 PM, MRAB wrote:

On 2012-10-15 22:09, someone wrote:


See this:

==
In [5]: Dx = numpy.matrix('1 0 0; 0 0.5 -0.5; 0 -0.5 1.5')

In [6]: Dx
Out[6]:
matrix([[ 1. ,  0. ,  0. ],
  [ 0. ,  0.5, -0.5],
  [ 0. , -0.5,  1.5]])
==



Ok... So now test = 33 and instead of the value 1.5 I want to use the
value of "test" and put it directly into the matrix (or array):

==
In [7]: test=33

In [8]: Dx = numpy.matrix('1 0 0; 0 0.5 -0.5; 0 -0.5 test')
---

NameError Traceback (most recent call
last)
/home/user/something/ in ()
> 1 Dx = numpy.matrix('1 0 0; 0 0.5 -0.5; 0 -0.5 test')

/usr/lib/python2.7/dist-packages/numpy/matrixlib/defmatrix.pyc in
__new__(subtype, data, dtype, copy)
  252
  253 if isinstance(data, str):
--> 254 data = _convert_from_string(data)
  255
  256 # now convert data to an array
.. etc...
==



So obviously it doesn't understand that I want this:

==
In [21]: Dx[2,2]=test

In [22]: Dx
Out[22]:
matrix([[  1. ,   0. ,   0. ],
  [  0. ,  33. ,  -0.5],
  [  0. ,  -0.5,  33. ]])
==

Without having to manually change all the individual places using my
variables (test is actually many variables, not just one but I think you
should understand the problem now).


How to initialize my array directly using variables ?

It could also be that I wanted:

test11 = 1
test12 = 1.5
test13 = 2
test21 = 0
test22 = 5

Dx = numpy.matrix('test11 test12 test13; test21 test22 -0.5; 0 -0.5 1.5')

Etc... for many variables...

Appreciate ANY help, thank you very much!


What it prints should give you a hint:

 >>> Dx = numpy.matrix([[test11, test12, test13], [test21, test22,
-0.5], [0, -0.5, 1.5]])
 >>> Dx
matrix([[ 1. ,  1.5,  2. ],
 [ 0. ,  5. , -0.5],
 [ 0. , -0.5,  1.5]])


Uh, great - thank you very much!

As you maybe see, I'm only a python newbie so I'm not so good at 
understanding the error messages and reading the source code yet.


Thank you very much for the solution to the problem! It's highly 
appreciated. Thanks.



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


RE: Tkinter how to access the widget by name

2012-10-15 Thread Prasad, Ramit
 ? wrote:
> I'm a little teapot ... himself the question: if I want to appeal to the 
> widget, knowing his name... ?
> 
> # appropriated the name of the widget
> label = Label(frame, width = 40, text='text', name = 'name')
> ...
> name_='name'
> configure(name_)
> ...
> def configure(name_)
> #And how can that be?
> # At least let the text you want to change 
> 
> I beg you ..
> --

I am unfamiliar with Tkinter, so this might not be very helpful.

Usually with the GUI I have created before I uses classes and store 
the widgets inside the classes. That makes it easier to use
`self.widgetname` or `getattr(self, widgetname)`. If that is not
something you can instead store the attributes in a list/dictionary.
In both cases make sure not to have multiple widgets created with
the same name.

Note the following is all untested and should be considered pseudo-code.

widgets = {}
label = Label(frame, width = 40, text='text', name = 'name')
widgets['name'] = label

def configure(name_):
widget = widgets[name_] 

OR

widgets = []
label = Label(frame, width = 40, text='text', name = 'name')
widgets.append( label )

def configure(name_):
found = False
for w in widgets:
 if w.name == name_: # No idea how to get name from Tk widget
   found = True
   break
 if found:
# configure here


Ramit Prasad


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numpy - 2D matrix/array - initialization like in Matlab...

2012-10-15 Thread Emile van Sebille

someone wrote:

How to initialize my array directly using variables ?

It could also be that I wanted:

test11 = 1
test12 = 1.5
test13 = 2
test21 = 0
test22 = 5

Dx = numpy.matrix('test11 test12 test13; test21 test22 -0.5; 0 -0.5 1.5')

Etc... for many variables...

Appreciate ANY help, thank you very much!


You could use string interpolation:

Dx = numpy.matrix('%s %s %s; %s %s -0.5; 0 -0.5 1.5'
  % (test11 test12 test13 test21 test22))


Emile

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


Re: numpy - 2D matrix/array - initialization like in Matlab...

2012-10-15 Thread Joshua Landau
On 15 October 2012 22:09, someone  wrote:

>
> See this:
>
> ==**
> In [5]: Dx = numpy.matrix('1 0 0; 0 0.5 -0.5; 0 -0.5 1.5')
>
> In [6]: Dx
> Out[6]:
> matrix([[ 1. ,  0. ,  0. ],
> [ 0. ,  0.5, -0.5],
> [ 0. , -0.5,  1.5]])
> ==**
>




> Without having to manually change all the individual places using my
> variables (test is actually many variables, not just one but I think you
> should understand the problem now).
>
>
> How to initialize my array directly using variables ?
>
> It could also be that I wanted:
>
> test11 = 1
> test12 = 1.5
> test13 = 2
> test21 = 0
> test22 = 5
>
> Dx = numpy.matrix('test11 test12 test13; test21 test22 -0.5; 0 -0.5 1.5')
>
> Etc... for many variables...
>
> Appreciate ANY help, thank you very much!


 Well, I don't know that much on Numpy (I've only ever used the basic
stuff), but Ian Kelly's probably right. If you can't "just use" a list, why
don't you convert it?

def matrixstring2lists(string, lookup_chain):
> stringmatrix = [substr.split() for substr in string.split(";")]



return [
> [
> lookup_chain[item] if item.isidentifier() else eval(item)
> for item in items
> ]
> for items in stringmatrix
> ]



# TESTS ##
> import builtins



## {{{ http://code.activestate.com/recipes/305268/ (r2)
> class Chainmap(dict):
> """Combine multiple mappings for sequential lookup.



For example, to emulate Python's normal lookup sequence:
> import __builtin__
> pylookup = Chainmap(locals(), globals(), vars(__builtin__))
> """
> def __init__(self, *maps):
> self._maps = maps
> def __getitem__(self, key):
> for mapping in self._maps:
> try:
> return mapping[key]
> except KeyError:
> pass
> raise KeyError(key)
> ## end of http://code.activestate.com/recipes/305268/ }}}


> test11 = 1
> test12 = 1.5
> test13 = 2
> test21 = 0
> test22 = 5



print(matrixstring2lists(
> 'test11 test12 test13; test21 test22 -0.5; 0 -0.5 1.5',
> Chainmap(locals(), globals(), vars(__builtins__))
> ))


That said, calling "matrixstring2lists" requires inputting a mapping from
the local scope, so I don't see how it could get much simpler to call
(minus removing "vars(__builtins__)" unless you *really* want that for some
reason.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numpy - 2D matrix/array - initialization like in Matlab...

2012-10-15 Thread MRAB

On 2012-10-15 22:09, someone wrote:


See this:

==
In [5]: Dx = numpy.matrix('1 0 0; 0 0.5 -0.5; 0 -0.5 1.5')

In [6]: Dx
Out[6]:
matrix([[ 1. ,  0. ,  0. ],
  [ 0. ,  0.5, -0.5],
  [ 0. , -0.5,  1.5]])
==



Ok... So now test = 33 and instead of the value 1.5 I want to use the
value of "test" and put it directly into the matrix (or array):

==
In [7]: test=33

In [8]: Dx = numpy.matrix('1 0 0; 0 0.5 -0.5; 0 -0.5 test')
---
NameError Traceback (most recent call last)
/home/user/something/ in ()
> 1 Dx = numpy.matrix('1 0 0; 0 0.5 -0.5; 0 -0.5 test')

/usr/lib/python2.7/dist-packages/numpy/matrixlib/defmatrix.pyc in
__new__(subtype, data, dtype, copy)
  252
  253 if isinstance(data, str):
--> 254 data = _convert_from_string(data)
  255
  256 # now convert data to an array
.. etc...
==



So obviously it doesn't understand that I want this:

==
In [21]: Dx[2,2]=test

In [22]: Dx
Out[22]:
matrix([[  1. ,   0. ,   0. ],
  [  0. ,  33. ,  -0.5],
  [  0. ,  -0.5,  33. ]])
==

Without having to manually change all the individual places using my
variables (test is actually many variables, not just one but I think you
should understand the problem now).


How to initialize my array directly using variables ?

It could also be that I wanted:

test11 = 1
test12 = 1.5
test13 = 2
test21 = 0
test22 = 5

Dx = numpy.matrix('test11 test12 test13; test21 test22 -0.5; 0 -0.5 1.5')

Etc... for many variables...

Appreciate ANY help, thank you very much!


What it prints should give you a hint:

>>> Dx = numpy.matrix([[test11, test12, test13], [test21, test22, 
-0.5], [0, -0.5, 1.5]])

>>> Dx
matrix([[ 1. ,  1.5,  2. ],
[ 0. ,  5. , -0.5],
[ 0. , -0.5,  1.5]])

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


Re: How to use "while" within the command in -c option of python?

2012-10-15 Thread Joshua Landau
On 13 October 2012 17:38, Joshua Landau  wrote:

> This here isn't a flaw in Python, though. It's a flaw in the command-line
> interpreter. By putting it all on one line, you are effectively saying:
> "group these". Which is the same as an "if True:" block, and some things
> like Reinteract even supply a grouping block like "build".
>
> That said, because some shells suck it would be nice if:
>
>> python -c "a=1\nif a:print(a)"
>
> worked (just for -c).
>
>
And, spurred on by another thread, this has become possible.

Make a file like so, install it if you wish.

import sys
> evaluable = sys.argv[1].encode("utf8").decode("unicode_escape")
> exec(evaluable)


This lets you do this:

python unicode_escape.py "a = []##\nfor x in range(100):##\n
>  a.append(x)##\n  a.append(x**2)##\nprint(a)"


It's ugly, but it works and only takes one line.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numpy - 2D matrix/array - initialization like in Matlab...

2012-10-15 Thread Ian Kelly
On Oct 15, 2012 3:12 PM, "someone"  wrote:
> How to initialize my array directly using variables ?

Why not just use the list-of-lists constructor instead of the string
constructor?

m = numpy.matrix([[1,2,3],[4,5,6],[7,8,test]])
-- 
http://mail.python.org/mailman/listinfo/python-list


numpy - 2D matrix/array - initialization like in Matlab...

2012-10-15 Thread someone


See this:

==
In [5]: Dx = numpy.matrix('1 0 0; 0 0.5 -0.5; 0 -0.5 1.5')

In [6]: Dx
Out[6]:
matrix([[ 1. ,  0. ,  0. ],
[ 0. ,  0.5, -0.5],
[ 0. , -0.5,  1.5]])
==



Ok... So now test = 33 and instead of the value 1.5 I want to use the 
value of "test" and put it directly into the matrix (or array):


==
In [7]: test=33

In [8]: Dx = numpy.matrix('1 0 0; 0 0.5 -0.5; 0 -0.5 test')
---
NameError Traceback (most recent call last)
/home/user/something/ in ()
> 1 Dx = numpy.matrix('1 0 0; 0 0.5 -0.5; 0 -0.5 test')

/usr/lib/python2.7/dist-packages/numpy/matrixlib/defmatrix.pyc in 
__new__(subtype, data, dtype, copy)

252
253 if isinstance(data, str):
--> 254 data = _convert_from_string(data)
255
256 # now convert data to an array
.. etc...
==



So obviously it doesn't understand that I want this:

==
In [21]: Dx[2,2]=test

In [22]: Dx
Out[22]:
matrix([[  1. ,   0. ,   0. ],
[  0. ,  33. ,  -0.5],
[  0. ,  -0.5,  33. ]])
==

Without having to manually change all the individual places using my 
variables (test is actually many variables, not just one but I think you 
should understand the problem now).



How to initialize my array directly using variables ?

It could also be that I wanted:

test11 = 1
test12 = 1.5
test13 = 2
test21 = 0
test22 = 5

Dx = numpy.matrix('test11 test12 test13; test21 test22 -0.5; 0 -0.5 1.5')

Etc... for many variables...

Appreciate ANY help, thank you very much!

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


Re: how to insert random error in a programming

2012-10-15 Thread Victor Stinner
Try fuzzing. Examples:
http://pypi.python.org/pypi/fusil/
http://peachfuzzer.com/

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


Re: how to insert random error in a programming

2012-10-15 Thread Mark Lawrence

On 15/10/2012 20:51, Chris Angelico wrote:

On Tue, Oct 16, 2012 at 6:28 AM, Mark Lawrence  wrote:

I like clearly written code like this

"
d = {}
for c in (65, 97):
 for i in range(26):
 d[chr(i+c)] = chr((i+13) % 26 + c)

print "".join([d.get(c, c) for c in s])


Surely there's a shorter way to rot13 a piece of text? CODE GOLF!

At very least, a single cryptic expression in place of your nice clear
loops MUST be an improvement.

d = dict((chr(i+c),chr((i+13)%26+c))for i in range(26)for c in(65,97))

And with superfluous spaces removed like that, it takes 0.02
jiggawatts less power in DeLorean Python.

ChrisA



How dare you Sir, they're most certainly *NOT* my loops!!!

--
Cheers.

Mark Lawrence.

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


Re: how to insert random error in a programming

2012-10-15 Thread Chris Angelico
On Tue, Oct 16, 2012 at 6:28 AM, Mark Lawrence  wrote:
> I like clearly written code like this
>
> "
> d = {}
> for c in (65, 97):
> for i in range(26):
> d[chr(i+c)] = chr((i+13) % 26 + c)
>
> print "".join([d.get(c, c) for c in s])

Surely there's a shorter way to rot13 a piece of text? CODE GOLF!

At very least, a single cryptic expression in place of your nice clear
loops MUST be an improvement.

d = dict((chr(i+c),chr((i+13)%26+c))for i in range(26)for c in(65,97))

And with superfluous spaces removed like that, it takes 0.02
jiggawatts less power in DeLorean Python.

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


Re: MySQL with Python

2012-10-15 Thread Roy Smith
In article ,
 Dennis Lee Bieber  wrote:

> For routine database /access/ (that is, someone has created the
> database user account that will be used), MySQLdb is the Python adapter
> to connect to the server. For using THAT, you basically need to know SQL
> (MySQL's flavor in particular), along with understanding the DB-API 2
> specification (PEP-249) with the MySQLdb documentation (which explains
> any limitations or specifics; see http://mysql-python.sourceforge.net/ )

Another possibility is to use some sort of ORM (Object Relational 
Mapper), which provides an abstraction layer on top of the raw SQL 
layer.  Two examples are SQLAlchemy (http://www.sqlalchemy.org/) and 
Django (https://www.djangoproject.com/).

A thread on Stack Overflow (http://stackoverflow.com/questions/53428) 
mentions some additional Python ORMs you might want to explore.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to insert random error in a programming

2012-10-15 Thread Mark Lawrence

On 15/10/2012 20:10, Joshua Landau wrote:

On 15 October 2012 14:55, Debashish Saha  wrote:


how to insert random error in a programming?



You could always just *write* the code with random errors from the start.
Try random code, like this:

from collections import defaultdict as ð

def ire(ł, æ=[]):
yield [ð(bool, {æ and æ[0]or object(): True}) [ł[0]] or [lambda: (yield
ire(((æ.append(object()), æ[0])[0], ł))), int][(ł>ł[:3])|(ł<=ł[:2])]() or
[1]][0]
print(list(list(ire([2, 3, 3]))[0]))



Note that being random code this does nothing other than confuse people as
to why it does what it does do even though that is nothing other than the
mentioned confusion of others into its purpose.





I like clearly written code like this

"
s = """Gur Mra bs Clguba, ol Gvz Crgref

Ornhgvshy vf orggre guna htyl.
Rkcyvpvg vf orggre guna vzcyvpvg.
Fvzcyr vf orggre guna pbzcyrk.
Pbzcyrk vf orggre guna pbzcyvpngrq.
Syng vf orggre guna arfgrq.
Fcnefr vf orggre guna qrafr.
Ernqnovyvgl pbhagf.
Fcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf.
Nygubhtu cenpgvpnyvgl orngf chevgl.
Reebef fubhyq arire cnff fvyragyl.
Hayrff rkcyvpvgyl fvyraprq.
Va gur snpr bs nzovthvgl, ershfr gur grzcgngvba gb thrff.
Gurer fubhyq or bar-- naq cersrenoyl bayl bar --boivbhf jnl gb qb vg.
Nygubhtu gung jnl znl abg or boivbhf ng svefg hayrff lbh'er Qhgpu.
Abj vf orggre guna arire.
Nygubhtu arire vf bsgra orggre guna *evtug* abj.
Vs gur vzcyrzragngvba vf uneq gb rkcynva, vg'f n onq vqrn.
Vs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn.
Anzrfcnprf ner bar ubaxvat terng vqrn -- yrg'f qb zber bs gubfr!"""

d = {}
for c in (65, 97):
for i in range(26):
d[chr(i+c)] = chr((i+13) % 26 + c)

print "".join([d.get(c, c) for c in s])
"

--
Cheers.

Mark Lawrence.

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


Re: Exception Messages

2012-10-15 Thread Terry Reedy

On 10/15/2012 12:22 PM, John Gordon wrote:

In  MRAB 
 writes:


Why wasn't the message printed out?


You didn't add a __str__ method:



class PvCamError(Exception):
  def __init__(self, msg):
  self.msg = msg
  def __str__(self):
  return self.msg


Wouldn't PvCamError inherit __str__() from Exception?


Exception instances get a .args attibute set to the arguments of the 
class call and printed in the .__str__ message.


>>> dir(Exception())
['__cause__', '__class__', '__context__', '__delattr__', '__dict__', 
'__dir__', '__doc__', '__eq__', '__format__', '__ge__', 
'__getattribute__', '__gt__', '__hash__', '__init__', '__le__', 
'__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', 
'__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', 
'__subclasshook__', '__suppress_context__', '__traceback__', 'args', 
'with_traceback']

>>> Exception('abc', 1)
Exception('abc', 1)

So class MyError(Exception) will get that basic default behavior. For 
fancier printing, one needs a fancier .__str__ method ;-).


--
Terry Jan Reedy

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


Re: how to insert random error in a programming

2012-10-15 Thread Joshua Landau
On 15 October 2012 14:55, Debashish Saha  wrote:

> how to insert random error in a programming?
>

You could always just *write* the code with random errors from the start.
Try random code, like this:

from collections import defaultdict as ð
> def ire(ł, æ=[]):
> yield [ð(bool, {æ and æ[0]or object(): True}) [ł[0]] or [lambda: (yield
> ire(((æ.append(object()), æ[0])[0], ł))), int][(ł>ł[:3])|(ł<=ł[:2])]() or
> [1]][0]
> print(list(list(ire([2, 3, 3]))[0]))


Note that being random code this does nothing other than confuse people as
to why it does what it does do even though that is nothing other than the
mentioned confusion of others into its purpose.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to insert random error in a programming

2012-10-15 Thread Chris Angelico
On Tue, Oct 16, 2012 at 4:18 AM, Serhiy Storchaka  wrote:
> On 15.10.12 17:04, Chris Angelico wrote:
>> On Tue, Oct 16, 2012 at 12:55 AM, Debashish Saha  wrote:
>>> how to insert random error in a programming?
>>
>> how to ask question good in forumming?
>> http://www.catb.org/~esr/faqs/smart-questions.html
>>
>> But here's one way to do it:
>>
>> raise 
>> random.choice((OSError,IOError,ZeroDivisionError,UnicodeDecodeError,AssertionError))()
>
> I think OP means something like
>
> programming[:0] = 
> random.choice((OSError,IOError,ZeroDivisionError,UnicodeDecodeError,AssertionError))()

Ah, good point. Though it's worth noting that my version will happily
raise a NameError under certain circumstances, while yours will never
insert a NameError into programming.

This is potentially very important when inserting random errors.

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


Re: how to insert random error in a programming

2012-10-15 Thread Emile van Sebille

Debashish Saha wrote:

how to insert random error in a programming?


Make the changes late in the day then leave for the weekend?

Emile

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


Re: how to insert random error in a programming

2012-10-15 Thread Gary Herron

On 10/15/2012 06:55 AM, Debashish Saha wrote:

how to insert random error in a programming?


Drink several beers before you start programming. :-)



--
Dr. Gary Herron
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418

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


Re: Exception Messages

2012-10-15 Thread Wanderer
On Monday, October 15, 2012 1:34:24 PM UTC-4, MRAB wrote:
> On 2012-10-15 18:18, Wanderer wrote:
> 
> > On Monday, October 15, 2012 12:34:53 PM UTC-4, MRAB wrote:
> 
> >
> 
> >>
> 
> >> Yes, but you've put the message in msg, and Exception doesn't have that
> 
> >>
> 
> >> attribute.
> 
> >>
> 
> >
> 
> > That's weird. I got this Exception class definition idea from this post by 
> > Guido van Rostrum, Where he gives this main function to look like
> 
> >
> 
> > import sys
> 
> > import getopt
> 
> >
> 
> > class Usage(Exception):
> 
> >  def __init__(self, msg):
> 
> >  self.msg = msg
> 
> >
> 
> > def main(argv=None):
> 
> >  if argv is None:
> 
> >  argv = sys.argv
> 
> >  try:
> 
> >  try:
> 
> >  opts, args = getopt.getopt(argv[1:], "h", ["help"])
> 
> >  except getopt.error, msg:
> 
> >   raise Usage(msg)
> 
> >  # more code, unchanged
> 
> >  except Usage, err:
> 
> >  print >>sys.stderr, err.msg
> 
> >  print >>sys.stderr, "for help use --help"
> 
> >  return 2
> 
> >
> 
> > if __name__ == "__main__":
> 
> >  sys.exit(main())
> 
> >
> 
> >
> 
> >
> 
> >
> 
> > http://www.artima.com/weblogs/viewpost.jsp?thread=4829
> 
> >
> 
> >
> 
> Note how it explicitly prints err.msg.

Not in the raise statement. 

Adding the def __str__ made it work for me.
Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exception Messages

2012-10-15 Thread MRAB

On 2012-10-15 18:18, Wanderer wrote:

On Monday, October 15, 2012 12:34:53 PM UTC-4, MRAB wrote:



Yes, but you've put the message in msg, and Exception doesn't have that

attribute.



That's weird. I got this Exception class definition idea from this post by 
Guido van Rostrum, Where he gives this main function to look like

import sys
import getopt

class Usage(Exception):
 def __init__(self, msg):
 self.msg = msg

def main(argv=None):
 if argv is None:
 argv = sys.argv
 try:
 try:
 opts, args = getopt.getopt(argv[1:], "h", ["help"])
 except getopt.error, msg:
  raise Usage(msg)
 # more code, unchanged
 except Usage, err:
 print >>sys.stderr, err.msg
 print >>sys.stderr, "for help use --help"
 return 2

if __name__ == "__main__":
 sys.exit(main())




http://www.artima.com/weblogs/viewpost.jsp?thread=4829



Note how it explicitly prints err.msg.

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


Re: Feedback on my python framework I'm building.

2012-10-15 Thread Roel Schroeven

MRAB schreef:

On 2012-10-14 23:38, Dave Angel wrote:

On 10/14/2012 08:48 AM, Roy Smith wrote:

In article <507a3365$0$6574$c3e8da3$54964...@news.astraweb.com>,
 Steven D'Aprano  wrote:


Remember using PEEK and POKE commands with BASIC back in
1978? Pretty much impossible in Python.

But, trivial to implement as an extension :-)

PEEK and POKE were intended to be used with memory mapped devices.
Simplest example is the 6502 chip, which had no I/O bus -- it was all
memory mapped.  Want to change baud rate?  poke a byte somewhere.

These days, the only device I can think of that's usually memory mapped
is the video.  And few programs talk to it that way.

Now, INP and OUT (or various similar names) were for doing port I/o.
But I suspect that modern systems aren't going to let you do much of
that either.


It depends on the CPU. Some have specialised instructions for I/O,
others don't.


I think Roy Smith meant that the OS on modern systems generally prevents 
direct access from user space to either memory mapped I/O or port mapped 
I/O. Embedded systems might allow direct access, but AFAIK Python 
doesn't run on those.


Best regards,
Roel

--
"Too often we hold fast to the cliches of our forebears. We subject all
facts to a prefabricated set of interpretations. Too often we enjoy the
comfort of opinion without the discomfort of thought."
-- John F Kennedy

r...@roelschroeven.net

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


Re: Exception Messages

2012-10-15 Thread Wanderer
On Monday, October 15, 2012 1:18:52 PM UTC-4, Wanderer wrote:
> On Monday, October 15, 2012 12:34:53 PM UTC-4, MRAB wrote:
> 
> 
> 
> > 
> 
> > Yes, but you've put the message in msg, and Exception doesn't have that
> 
> > 
> 
> > attribute.
> 
> > 
> 
> 
> 
> That's weird. I got this Exception class definition idea from this post by 
> Guido van Rostrum, Where he gives this main function to look like
> 
> 
> 
> import sys
> 
> import getopt
> 
> 
> 
> class Usage(Exception):
> 
> def __init__(self, msg):
> 
> self.msg = msg
> 
> 
> 
> def main(argv=None):
> 
> if argv is None:
> 
> argv = sys.argv
> 
> try:
> 
> try:
> 
> opts, args = getopt.getopt(argv[1:], "h", ["help"])
> 
> except getopt.error, msg:
> 
>  raise Usage(msg)
> 
> # more code, unchanged
> 
> except Usage, err:
> 
> print >>sys.stderr, err.msg
> 
> print >>sys.stderr, "for help use --help"
> 
> return 2
> 
> 
> 
> if __name__ == "__main__":
> 
> sys.exit(main())
> 
> 
> 
> 
> 
> 
> 
> 
> 
> http://www.artima.com/weblogs/viewpost.jsp?thread=4829

Oops. I meant Guido van Rossum
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to insert random error in a programming

2012-10-15 Thread Serhiy Storchaka
On 15.10.12 17:04, Chris Angelico wrote:
> On Tue, Oct 16, 2012 at 12:55 AM, Debashish Saha  wrote:
>> how to insert random error in a programming?
> 
> how to ask question good in forumming?
> http://www.catb.org/~esr/faqs/smart-questions.html
> 
> But here's one way to do it:
> 
> raise 
> random.choice((OSError,IOError,ZeroDivisionError,UnicodeDecodeError,AssertionError))()

I think OP means something like

programming[:0] = 
random.choice((OSError,IOError,ZeroDivisionError,UnicodeDecodeError,AssertionError))()


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


Re: Exception Messages

2012-10-15 Thread Wanderer
On Monday, October 15, 2012 12:34:53 PM UTC-4, MRAB wrote:

> 
> Yes, but you've put the message in msg, and Exception doesn't have that
> 
> attribute.
> 

That's weird. I got this Exception class definition idea from this post by 
Guido van Rostrum, Where he gives this main function to look like

import sys
import getopt

class Usage(Exception):
def __init__(self, msg):
self.msg = msg

def main(argv=None):
if argv is None:
argv = sys.argv
try:
try:
opts, args = getopt.getopt(argv[1:], "h", ["help"])
except getopt.error, msg:
 raise Usage(msg)
# more code, unchanged
except Usage, err:
print >>sys.stderr, err.msg
print >>sys.stderr, "for help use --help"
return 2

if __name__ == "__main__":
sys.exit(main())




http://www.artima.com/weblogs/viewpost.jsp?thread=4829


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


Re: portable unicode literals

2012-10-15 Thread Serhiy Storchaka

On 15.10.12 16:05, Ulrich Eckhardt wrote:

I need a little nudge in the right direction, as I'm misunderstanding
something concerning string literals in Python 2 and 3. In Python 2.7,
b'' and '' are byte strings, while u'' is a unicode literal. In Python
3.2, b'' is a byte string and '' is a unicode literal, while u'' is a
syntax error.

This actually came as a surprise to me, I assumed that using b'' I could
portably create a byte string (which is true) and using u'' I could
portably create a unicode string (which is not true). This feature would
help porting code between both versions. While this is a state I can
live with, I wonder what the rationale for this is.


  from __future__ import unicode_literals

And now you can portable use b'' for a byte string and '' for a unicode 
string. When you will drop Python 2 support then just remove import from 
__future__.



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


Re: how to insert random error in a programming

2012-10-15 Thread Jean-Michel Pichavant
- Original Message -

[snip a huge list of advices example and insights]

> Then list the description on the homework
> assignment.
> 
> --
> 
> DaveA

Like the youngsters write:

"/bow"

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


Re: Exception Messages

2012-10-15 Thread Dave Angel
On 10/15/2012 12:34 PM, MRAB wrote:
> On 2012-10-15 17:22, John Gordon wrote:
>> In  MRAB
>>  writes:
>>
>>> > Why wasn't the message printed out?
>>>
>>> You didn't add a __str__ method:
>>
>>> class PvCamError(Exception):
>>>  def __init__(self, msg):
>>>  self.msg = msg
>>>  def __str__(self):
>>>  return self.msg
>>
>> Wouldn't PvCamError inherit __str__() from Exception?
>>
> Yes, but you've put the message in msg, and Exception doesn't have that
> attribute.
>
> An alternative approach would be:
>
> class PvCamError(Exception):
> pass
>

Wouldn't another approach be for this __init__() method to call the
base-class __init__() method with whatever data it needs?



-- 

DaveA

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


Re: Exception Messages

2012-10-15 Thread MRAB

On 2012-10-15 17:22, John Gordon wrote:

In  MRAB 
 writes:


> Why wasn't the message printed out?

You didn't add a __str__ method:



class PvCamError(Exception):
 def __init__(self, msg):
 self.msg = msg
 def __str__(self):
 return self.msg


Wouldn't PvCamError inherit __str__() from Exception?


Yes, but you've put the message in msg, and Exception doesn't have that
attribute.

An alternative approach would be:

class PvCamError(Exception):
pass

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


Re: Exception Messages

2012-10-15 Thread John Gordon
In  MRAB 
 writes:

> > Why wasn't the message printed out?
>
> You didn't add a __str__ method:

> class PvCamError(Exception):
>  def __init__(self, msg):
>  self.msg = msg
>  def __str__(self):
>  return self.msg

Wouldn't PvCamError inherit __str__() from Exception?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Exception Messages

2012-10-15 Thread MRAB

On 2012-10-15 17:00, Wanderer wrote:

How do you get Exceptions to print messages? I have an exception defined like 
this

class PvCamError(Exception):
 def __init__(self, msg):
 self.msg = msg

But when the error is raised I get this:

Traceback (most recent call last):
   File 
"C:\Python27\lib\site-packages\ipython-0.12.1-py2.7.egg\IPython\core\interactiveshell.py",
 line 2538, in run_code
 exec code_obj in self.user_global_ns, self.user_ns
   File "", line 1, in 
 import S477Test
   File "U:\workspace\camera\src\S477Test.py", line 13, in 
 camera.getSerialNum()
   File "U:\workspace\camera\src\S477.py", line 131, in getSerialNum
 num = self.pl.getParamValue(pvcamConstants.PARAM_HEAD_SER_NUM_ALPHA)
   File "U:\workspace\camera\src\pvcam.py", line 261, in getParamValue
 raise PvCamError("Unhandled Type: {0}".format(attype))
PvCamError

Why wasn't the message printed out?


You didn't add a __str__ method:

class PvCamError(Exception):
def __init__(self, msg):
self.msg = msg
def __str__(self):
return self.msg

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


Re: how to insert random error in a programming

2012-10-15 Thread John Gordon
In  Debashish Saha 
 writes:

> how to insert random error in a programming?

Open the program source file and replace the Nth character with a random
character.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Exception Messages

2012-10-15 Thread Wanderer
How do you get Exceptions to print messages? I have an exception defined like 
this

class PvCamError(Exception):
def __init__(self, msg):
self.msg = msg

But when the error is raised I get this:

Traceback (most recent call last):
  File 
"C:\Python27\lib\site-packages\ipython-0.12.1-py2.7.egg\IPython\core\interactiveshell.py",
 line 2538, in run_code
exec code_obj in self.user_global_ns, self.user_ns
  File "", line 1, in 
import S477Test
  File "U:\workspace\camera\src\S477Test.py", line 13, in 
camera.getSerialNum()
  File "U:\workspace\camera\src\S477.py", line 131, in getSerialNum
num = self.pl.getParamValue(pvcamConstants.PARAM_HEAD_SER_NUM_ALPHA)
  File "U:\workspace\camera\src\pvcam.py", line 261, in getParamValue
raise PvCamError("Unhandled Type: {0}".format(attype))
PvCamError

Why wasn't the message printed out?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's the tidy/elegant way to protect this against null/empty parameters?

2012-10-15 Thread Terry Reedy

On 10/15/2012 7:23 AM, tinn...@isbd.co.uk wrote:

I want to fix an error in some code I have installed, however I don't
really want to just bodge it.

The function producing the error is:-

 def get_text(self, idx):   # override !
 node = self.items[idx]

 a= [
 ", ".join(node.tags),
 node.comment,
 node.folderName,
 cd2rd(node.date),
 node.name,
 '[' + self.rating_stars[node.rating] + ']'
 ] [self.select]

 return a


The error occurs when node[] (or at least its members) turn out to be
empty,


This is not the problem.

> you get a Traceback that ends with:-


   File "/usr/lib/jbrout/jbrout/listview.py", line 608, in draw_cell 
layout.set_text(self.get_text(thumbnail_num))
   File "/usr/lib/jbrout/jbrout.py", line 325, in get_text ", ".join(node.tags),
   TypeError: sequence item 0: expected string, NoneType found


The specific problem is that node.tags is supposed to be a sequence of 
strings and somehow one instead has None as the first, and probably last 
item. This was likely intended to indicate an empty list, but the way to 
do that is to have a empty list, which would have worked just fine. In 
other words, the likely problem is that node.tags is *not* an empty 
sequence when it should be.


>>> ','.join([None])
Traceback (most recent call last):
  File "", line 1, in 
','.join([None])
TypeError: sequence item 0: expected str instance, NoneType found
>>> ','.join([])
''

--
Terry Jan Reedy

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


Re: how to insert random error in a programming

2012-10-15 Thread Neal Becker
Debashish Saha wrote:

> how to insert random error in a programming?

Apparently, giving it to Microsoft will work.

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


Re: how to insert random error in a programming

2012-10-15 Thread Mark Lawrence

On 15/10/2012 14:55, Debashish Saha wrote:

how to insert random error in a programming?



Just use some of my code, it's far more random than that suggested by 
others who've replied to your query.


--
Cheers.

Mark Lawrence.

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


Re: MySQL with Python

2012-10-15 Thread Anurag Chourasia
Don't worry about what book you have (or don't have) in your
Library..And let this not dictate your technology stack.

PostgreSQL is one of the popular choice and you will never be short of
documentation...Just Google and you will find lot of helpful tutorials...

Regards,
Anurag

On Mon, Oct 15, 2012 at 10:47 AM, রুদ্র ব্যাণার্জী wrote:

> On Tue, 2012-10-16 at 01:01 +1100, Chris Angelico wrote:
> > But you may wish to consider using PostgreSQL instead.
> Thanks, as I am  very much new in database thing, I am not very aware of
> the options I have.
> But in my library, I did not found any thing on PostgreSQL.
> Though, I will google its support as well, can you kindly let me know if
> this is well documented. I can see there mailing list is quite active.
> So that may not be a problem though.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MySQL with Python

2012-10-15 Thread Chris Angelico
On Tue, Oct 16, 2012 at 1:47 AM, রুদ্র ব্যাণার্জী  wrote:
> On Tue, 2012-10-16 at 01:01 +1100, Chris Angelico wrote:
>> But you may wish to consider using PostgreSQL instead.
> Thanks, as I am  very much new in database thing, I am not very aware of
> the options I have.
> But in my library, I did not found any thing on PostgreSQL.
> Though, I will google its support as well, can you kindly let me know if
> this is well documented. I can see there mailing list is quite active.
> So that may not be a problem though.

Postgres itself: http://www.postgresql.org/

I posted a link to some Python-PGSQL libraries in my previous post.

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


Re: MySQL with Python

2012-10-15 Thread রুদ্র ব্যাণার্জী
On Tue, 2012-10-16 at 01:01 +1100, Chris Angelico wrote:
> But you may wish to consider using PostgreSQL instead. 
Thanks, as I am  very much new in database thing, I am not very aware of
the options I have.
But in my library, I did not found any thing on PostgreSQL. 
Though, I will google its support as well, can you kindly let me know if
this is well documented. I can see there mailing list is quite active.
So that may not be a problem though.

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


Re: how to insert random error in a programming

2012-10-15 Thread Dave Angel
On 10/15/2012 09:55 AM, Debashish Saha wrote:
> how to insert random error in a programming?

I don't see how this phrase makes any sense without a lot more context. 
If I add the words "I'd like to know" in front of the phrase, and
"session."  at the end (and add the word "a" as appropriate), the best
answer I'd come up with is to deprive the programmer of a lot of sleep
the night before.

If I just take the words in the phrase, and try to dream up the possible
ways they could be meant...

For example, perhaps you have a series of data, taken from some
experiment, and you want to "break" the data, to make it appear more
random (to fit the model less well).  You might just want to iterate
over the sample twice, once to calculate the average, min, and max. 
Then you might add to each sample a random signed value with a
distribution based on those three values.

Or you might be a teacher with a "perfect program," and you want to
(programmatically) change it slightly, and see how long it takes your
students to find the introduced error.  This seems to me to be an
extremely hard problem in the general case, though pretty easy for a
human.  Problem is that most random text changes will presumably cause
compile errors, or "not defined".  And those are trivial to find and fix
for an experienced programmer, though first year students might need the
practice.

Or you might be trying to get your module to simulate various errors,
randomly chosen.  In which case, see Chris's or jean-Michel's response.

Or you might be trying to cause other applications to crash, because
you're pretending to be a virus.

Or a dozen other things.

You get the random module byimport random.   But beyond that, we'd
have to understand your use case.  Start by mentioning Python version
and OS. Then give a brief summary of your level of experience in Python
and in other langugages.  Then list the description on the homework
assignment.

-- 

DaveA

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


Re: how to insert random error in a programming

2012-10-15 Thread Jean-Michel Pichavant
- Original Message -
> how to insert random error in a programming?
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

Here's an example

from random

raise Except(randome.randinteger(0,10,'error']): return

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


Re: how to insert random error in a programming

2012-10-15 Thread Chris Angelico
On Tue, Oct 16, 2012 at 12:55 AM, Debashish Saha  wrote:
> how to insert random error in a programming?

how to ask question good in forumming?
http://www.catb.org/~esr/faqs/smart-questions.html

But here's one way to do it:

raise 
random.choice((OSError,IOError,ZeroDivisionError,UnicodeDecodeError,AssertionError))()

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


Re: MySQL with Python

2012-10-15 Thread Demian Brecht

On 12-10-15 06:45 AM, রুদ্র ব্যাণার্জী wrote:

if yes, can you kindly suggest a book/reference on this?



There are a few different ways to connect to MySQL, two of which are:

For reference on connecting and querying MySQL through mysql-python, 
take a read through http://mysql-python.sourceforge.net/MySQLdb.html.


Another solution is to use SQLAlchemy (http://www.sqlalchemy.org/). The 
ORM abstracts a lot of the tedious SQL queries out for you and allows 
you to concentrate more on your application's logic.


--
Demian Brecht
@demianbrecht
http://demianbrecht.github.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: MySQL with Python

2012-10-15 Thread Chris Angelico
On Tue, Oct 16, 2012 at 12:45 AM, রুদ্র ব্যাণার্জী  wrote:
> Dear friends,
> I am starting a project of creating a database using mySQL(my first
> project with database).
> I went to my institute library and find that, all books are managing
> "mySQL with perl and php"
>
> I am new to python itself and gradually loving it. I mostly use it as an
> alternative of shell-script. Since learning a new language for every new
> project is not possible(its self assigned project, generally in free
> time), can I do a "mySQL with python?"
>
> if yes, can you kindly suggest a book/reference on this?

It's definitely possible. As far as I know, though, there's no inbuilt
support, so you'll need an add-on module. What platform are you
running on? On Debian Linux, for instance, you can simply "apt-get
install python-mysqldb".

But you may wish to consider using PostgreSQL instead. It's a
generally better database engine than MySQL, and is equally well
supported:

http://wiki.python.org/moin/PostgreSQL

Actually, to be quite honest, I'm surprised there's no module in the
Python stdlib for either of the above. Possibly because there are
several competing options.

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


Re: MySQL with Python

2012-10-15 Thread Anurag Chourasia
Yes you can. There are libraries available in python to make this happen.

Read this for a starter

http://dev.mysql.com/usingmysql/python/

Regards,
Anurag
On Oct 15, 2012 10:53 AM, "রুদ্র ব্যাণার্জী"  wrote:

> Dear friends,
> I am starting a project of creating a database using mySQL(my first
> project with database).
> I went to my institute library and find that, all books are managing
> "mySQL with perl and php"
>
> I am new to python itself and gradually loving it. I mostly use it as an
> alternative of shell-script. Since learning a new language for every new
> project is not possible(its self assigned project, generally in free
> time), can I do a "mySQL with python?"
>
> if yes, can you kindly suggest a book/reference on this?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


how to insert random error in a programming

2012-10-15 Thread Debashish Saha
how to insert random error in a programming?
-- 
http://mail.python.org/mailman/listinfo/python-list


MySQL with Python

2012-10-15 Thread রুদ্র ব্যাণার্জী
Dear friends,
I am starting a project of creating a database using mySQL(my first
project with database). 
I went to my institute library and find that, all books are managing
"mySQL with perl and php"

I am new to python itself and gradually loving it. I mostly use it as an
alternative of shell-script. Since learning a new language for every new
project is not possible(its self assigned project, generally in free
time), can I do a "mySQL with python?"

if yes, can you kindly suggest a book/reference on this?

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


Re: portable unicode literals

2012-10-15 Thread Alex Strickland

On 2012/10/15 03:05 PM, Ulrich Eckhardt wrote:


This actually came as a surprise to me, I assumed that using b'' I could
portably create a byte string (which is true) and using u'' I could
portably create a unicode string (which is not true). This feature would
help porting code between both versions. While this is a state I can
live with, I wonder what the rationale for this is.

!puzzled thanks


u'' is legal in 3.3 again.

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


RE: Fastest web framework

2012-10-15 Thread Andriy Kornatskyy

How fast python web frameworks reverse urls?

While routing is a mapping of incoming request to a handler, url reverse 
function is designed to build urls for those handlers. A web page may have a 
number of urls from few dozen to hundreds... all related to your web site (e.g. 
links between related pages, tag cloud, most viewed posts, etc).

Here is a benchmark for various web frameworks (django, flask, pyramid, tornado 
and wheezy.web):

http://mindref.blogspot.com/2012/10/python-web-reverse-urls-benchmark.html

Benchmark is executed in isolated environment using CPython 2.7. Source is here:

https://bitbucket.org/akorn/helloworld/src/tip/03-urls

Comments or suggestions are welcome.
 
Thanks.

Andriy Kornatskyy



> From: andriy.kornats...@live.com
> To: python-list@python.org
> Subject: Fastest web framework
> Date: Sun, 23 Sep 2012 12:19:16 +0300
>
>
> I have run recently a benchmark of a trivial 'hello world' application for 
> various python web frameworks (bottle, django, flask, pyramid, web.py, 
> wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might find 
> it interesting:
>
> http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html
>
> Comments or suggestions are welcome.
>
> Thanks.
>
> Andriy Kornatskyy
>
> --
> http://mail.python.org/mailman/listinfo/python-list
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's the tidy/elegant way to protect this against null/empty parameters?

2012-10-15 Thread Miki Tebeka
> I want to fix an error in some code I have installed, ...
Apart from all the reasons why it's bad (see the Python Zen #10). One way to do 
it is:
return [i or '' for i in a]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: portable unicode literals

2012-10-15 Thread Dave Angel
On 10/15/2012 09:05 AM, Ulrich Eckhardt wrote:
> Hi!
>
> I need a little nudge in the right direction, as I'm misunderstanding
> something concerning string literals in Python 2 and 3. In Python 2.7,
> b'' and '' are byte strings, while u'' is a unicode literal. In Python
> 3.2, b'' is a byte string and '' is a unicode literal, while u'' is a
> syntax error.
>
> This actually came as a surprise to me, I assumed that using b'' I
> could portably create a byte string (which is true) and using u'' I
> could portably create a unicode string (which is not true). This
> feature would help porting code between both versions. While this is a
> state I can live with, I wonder what the rationale for this is.
>
> !puzzled thanks
>
> Uli

Python 3.3 added that syntax, for easier porting.  You can now use
u"xyz" for a unicode string in both 2.x and 3.3

-- 

DaveA

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


Re: portable unicode literals

2012-10-15 Thread Steven D'Aprano
On Mon, 15 Oct 2012 15:05:01 +0200, Ulrich Eckhardt wrote:

> Hi!
> 
> I need a little nudge in the right direction, as I'm misunderstanding
> something concerning string literals in Python 2 and 3. In Python 2.7,
> b'' and '' are byte strings, while u'' is a unicode literal. In Python
> 3.2, b'' is a byte string and '' is a unicode literal, while u'' is a
> syntax error.
> 
> This actually came as a surprise to me, I assumed that using b'' I could
> portably create a byte string (which is true) and using u'' I could
> portably create a unicode string (which is not true). This feature would
> help porting code between both versions. While this is a state I can
> live with, I wonder what the rationale for this is.

It was a mistake that is corrected in Python 3.3.

You can now use u'' to create Unicode literals in both 2.x and 3.3 or 
better. This is a feature only designed for porting code though: you 
shouldn't use u'' in new code not intended for 2.x.


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


portable unicode literals

2012-10-15 Thread Ulrich Eckhardt

Hi!

I need a little nudge in the right direction, as I'm misunderstanding 
something concerning string literals in Python 2 and 3. In Python 2.7, 
b'' and '' are byte strings, while u'' is a unicode literal. In Python 
3.2, b'' is a byte string and '' is a unicode literal, while u'' is a 
syntax error.


This actually came as a surprise to me, I assumed that using b'' I could 
portably create a byte string (which is true) and using u'' I could 
portably create a unicode string (which is not true). This feature would 
help porting code between both versions. While this is a state I can 
live with, I wonder what the rationale for this is.


!puzzled thanks

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


Re: simple string format question

2012-10-15 Thread Dave Angel
On 10/15/2012 08:29 AM, Chris Rebert wrote:
> On Mon, Oct 15, 2012 at 5:12 AM, Neal Becker  wrote:
>> Is there a way to specify to format I want a floating point written with no 
>> more
>> than e.g., 2 digits after the decimal?  I tried {:.2f}, but then I get all
>> floats written with 2 digits, even if they are 0:
>>
>> 2.35 << yes, that's what I want
>> 2.00 << no, I want just 2 or 2.
> Not that I can find. Seems you'll have to implement it yourself.

To do it yourself, probably best to use a temp string value, created by
format "{: f}".  (Notice the space before the f, to reserve space for
the sign)  Then, slice that value to length 4 .  Finally, in your actual
format, use :5s for a format.  This should add the blanks for padding,
so other columns still line up.

>
> In the event that your project uses Django, there happens to be a
> template tag for this (pass it -2 in your case):
> https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#floatformat
>
> Cheers,
> Chris


-- 

DaveA

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


Re: simple string format question

2012-10-15 Thread Adrien

Le 15/10/2012 14:12, Neal Becker a écrit :

Is there a way to specify to format I want a floating point written with no more
than e.g., 2 digits after the decimal?  I tried {:.2f}, but then I get all
floats written with 2 digits, even if they are 0:

2.35 << yes, that's what I want
2.00 << no, I want just 2 or 2.


Maybe you're looking for "{:.3g}"

print "{:.3g}".format(2)
# '2'

print "{:.3g}".format(2.00)
# '2'

print "{:.3g}".format(2.35)
# '2.35'

print "{:.3g}".format(2.356)  # this rounds up
# '2.36'

Cheers,

-- Adrien

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


Re: simple string format question

2012-10-15 Thread Kamlesh Mutha
There doesn't seem to be any direct way to achieve this.

Maybe you can do something like this:

import math

x = 3.05

if math.modf(x)[0] != 0.0: print x


Cheers,
-Kamlesh




On Mon, Oct 15, 2012 at 5:59 PM, Chris Rebert  wrote:

> On Mon, Oct 15, 2012 at 5:12 AM, Neal Becker  wrote:
> > Is there a way to specify to format I want a floating point written with
> no more
> > than e.g., 2 digits after the decimal?  I tried {:.2f}, but then I get
> all
> > floats written with 2 digits, even if they are 0:
> >
> > 2.35 << yes, that's what I want
> > 2.00 << no, I want just 2 or 2.
>
> Not that I can find. Seems you'll have to implement it yourself.
>
>
> In the event that your project uses Django, there happens to be a
> template tag for this (pass it -2 in your case):
>
> https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#floatformat
>
> Cheers,
> Chris
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Faith waiting in the heart of a seed promises a miracle of life which it
can not prove!
-Ravindranath Tagore
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: simple string format question

2012-10-15 Thread Chris Rebert
On Mon, Oct 15, 2012 at 5:12 AM, Neal Becker  wrote:
> Is there a way to specify to format I want a floating point written with no 
> more
> than e.g., 2 digits after the decimal?  I tried {:.2f}, but then I get all
> floats written with 2 digits, even if they are 0:
>
> 2.35 << yes, that's what I want
> 2.00 << no, I want just 2 or 2.

Not that I can find. Seems you'll have to implement it yourself.


In the event that your project uses Django, there happens to be a
template tag for this (pass it -2 in your case):
https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#floatformat

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


simple string format question

2012-10-15 Thread Neal Becker
Is there a way to specify to format I want a floating point written with no 
more 
than e.g., 2 digits after the decimal?  I tried {:.2f}, but then I get all 
floats written with 2 digits, even if they are 0:

2.35 << yes, that's what I want
2.00 << no, I want just 2 or 2.

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


Re: What's the tidy/elegant way to protect this against null/empty parameters?

2012-10-15 Thread Roy Smith
In article <1b8tk9-un9@chris.zbmc.eu>, tinn...@isbd.co.uk wrote:

> The function producing the error is:-
> 
> def get_text(self, idx):   # override !
> node = self.items[idx]
> 
> a= [
> ", ".join(node.tags),
> node.comment,
> node.folderName,
> cd2rd(node.date),
> node.name,
> '[' + self.rating_stars[node.rating] + ']'
> ] [self.select]
> 
> return a
> 
> 
> The error occurs when node[] (or at least its members) turn out to be
> empty, you get a Traceback that ends with:-
> 
>   File "/usr/lib/jbrout/jbrout/listview.py", line 608, in draw_cell 
>   layout.set_text(self.get_text(thumbnail_num))
>   File "/usr/lib/jbrout/jbrout.py", line 325, in get_text ", 
>   ".join(node.tags),
>   TypeError: sequence item 0: expected string, NoneType found
> 
> Now its *probably* something higher up the tree causing the problem
> (it's only one particular image in 20 thousand or so that breaks
> things) but I really want to just get things working.  So, what's the
> neatest way to protect the get_text() method from empty data?

Well, you don't describe what get_text() is supposed to return  First, 
you build a list of what I'm guessing are all strings, then you index 
into it and return one of the values.  So, I'm guessing get_text() is 
supposed to return a string.

At a low level, you can certainly fix that by testing to see if 
self.items[idx] returns what you're expecting (an instance of Node?) and 
returning an empty string if it's not:

> def get_text(self, idx):   # override !
> node = self.items[idx]
> if not node:
> return ""
> 
> a= [
> ", ".join(node.tags),
> node.comment,
> node.folderName,
> cd2rd(node.date),
> node.name,
> '[' + self.rating_stars[node.rating] + ']'
> ] [self.select]
> 
> return a

Whether that makes sense in your program, I have no idea.  What does it 
mean for node to be empty?  Is this a normal occurrence?  If so, then 
your code needs to deal with properly (the suggest above being just one 
possible way).

Or, is it "impossible" for node to be empty?  In that case, that fact 
that it *is* empty is a bug, and the above suggestion will just hide the 
bug for one more level and make it that much harder to figure out what's 
really going on.  What you might really want to do is sprinkle your code 
with "assert node" statements.  This will force your program to crash 
and burn the first time node is empty, which might help you figure out 
why it is.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's the tidy/elegant way to protect this against null/empty parameters?

2012-10-15 Thread Chris Rebert
On Mon, Oct 15, 2012 at 4:23 AM,   wrote:
> I want to fix an error in some code I have installed, however I don't
> really want to just bodge it.

"bodge". Well, I learned a new word this morning!

> The function producing the error is:-
>
> def get_text(self, idx):   # override !
> node = self.items[idx]
>
> a= [
> ", ".join(node.tags),
> node.comment,
> node.folderName,
> cd2rd(node.date),
> node.name,
> '[' + self.rating_stars[node.rating] + ']'
> ] [self.select]
>
> return a
>
>
> The error occurs when node[] (or at least its members) turn out to be
> empty,

To be precise: when node.tags contains one or more `None`s (Python's
equivalent of what other languages call "null" or "nil").
That's what the traceback is saying.

> you get a Traceback that ends with:-
>
>   File "/usr/lib/jbrout/jbrout/listview.py", line 608, in draw_cell 
> layout.set_text(self.get_text(thumbnail_num))

Ah, so this is apparently regarding https://code.google.com/p/jbrout/
. Would have been nice not to have had to search and then only locate
it indirectly. Something to consider next time you write in...
Make sure you report your bug upstream!

>   File "/usr/lib/jbrout/jbrout.py", line 325, in get_text ", 
> ".join(node.tags),
>   TypeError: sequence item 0: expected string, NoneType found
>
> Now its *probably* something higher up the tree causing the problem
> (it's only one particular image in 20 thousand or so that breaks
> things) but I really want to just get things working.  So, what's the
> neatest way to protect the get_text() method from empty data?

Filter out the `None`s with a generator expression:
", ".join(tag for tag in node.tags if tag is not None),

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


Re: pyw program not displaying unicode characters properly

2012-10-15 Thread Roy Smith
In article ,
 Dennis Lee Bieber  wrote:

>   Classically, NNTP did not have "attachments" as seen in MIME email.

NNTP (Network News Transport Protocol) and SMTP (Simple Mail Transfer 
Protocol) are both just ways of shipping around messages.  Neither one 
really knows about attachments.  In both mail and news, "attachments" 
are a higher-level concept encoded inside the message content and 
managed by the various user applications.

>   It did have "binaries" in some encoding -- UUE, BASE64, or some
> newer format, but these encodings were the raw body of the post(s), not
> something "attached" as a separate file along with a text body.

This is all true of both mail and news, with only trivial changes of the 
formats and names of the encodings.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's the tidy/elegant way to protect this against null/empty parameters?

2012-10-15 Thread Paul Rubin
tinn...@isbd.co.uk writes:
> I want to fix an error in some code I have installed, however I don't
> really want to just bodge it. ...
> Now its *probably* something higher up the tree causing the problem
> (it's only one particular image in 20 thousand or so that breaks
> things) but I really want to just get things working.  

That means you do really want to just bodge it, doesn't it?  (I'm
reading "bodge" as something like "kludge" but maybe it means something
different.)

> So, what's the neatest way to protect the get_text() method from empty
> data?

I'd say the use of None as a picture is already a code smell: figure out
where it is coming from, and fix it.  Or, if you want to just bodge it
(by checking for None and returning the empty string or something)),
then try it and see if it helps.  I'm assuming this is something
noncritical that you're running on your own computer for convenience.  I
wouldn't ship code to a customer without a more careful fix.
-- 
http://mail.python.org/mailman/listinfo/python-list


What's the tidy/elegant way to protect this against null/empty parameters?

2012-10-15 Thread tinnews
I want to fix an error in some code I have installed, however I don't
really want to just bodge it.

The function producing the error is:-

def get_text(self, idx):   # override !
node = self.items[idx]

a= [
", ".join(node.tags),
node.comment,
node.folderName,
cd2rd(node.date),
node.name,
'[' + self.rating_stars[node.rating] + ']'
] [self.select]

return a


The error occurs when node[] (or at least its members) turn out to be
empty, you get a Traceback that ends with:-

  File "/usr/lib/jbrout/jbrout/listview.py", line 608, in draw_cell 
layout.set_text(self.get_text(thumbnail_num))
  File "/usr/lib/jbrout/jbrout.py", line 325, in get_text ", ".join(node.tags),
  TypeError: sequence item 0: expected string, NoneType found

Now its *probably* something higher up the tree causing the problem
(it's only one particular image in 20 thousand or so that breaks
things) but I really want to just get things working.  So, what's the
neatest way to protect the get_text() method from empty data?


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


Python stand alone Android Apps:)

2012-10-15 Thread michaeldavid1234567
Hi, Cote here, and I'm very pleased to announce that I've ported ALL my sl4a 
apps to eclipse apk, it embeds with the python interpreter, no need to install 
anything but the app off google play!

I have completed:

A) Android Eye (Computer Vision), that takes a picture and tells you what it is 
(Object Recognition):
https://play.google.com/store/apps/details?id=com.androideye.androideye

B) See Say (OCR) Picture to Speach, for the visually impaired.  You can 
literally have it read a book to you:
https://play.google.com/store/apps/details?id=com.seesay.seesay

C) See Say Translate (ocr that takes a page in any language, as a picture, then 
reads it back in english:) :
https://play.google.com/store/apps/details?id=com.seesay.seesaytranslate

D) Standardized IQ Test (based on the Stanfod-Binet Image/Problem Solving 
Section:
https://play.google.com/store/apps/details?id=com.iqtest.iqtest

E) AuraScope, a Chinese horoscope app with the added feature that it calibrates 
one's Aura (via image white content):
https://play.google.com/store/apps/details?id=com.aurahoroscope.aurahoroscope

F) Picture Drinks, an implementation of the Object Recognition, specific to 
your liquor bottle:) :
https://play.google.com/store/apps/details?id=com.picturedrinksnew.picturedrinksnew

G) Pocket Translator, a simple translator where you enter a language and get 
the results in English, good tool for traveling:
https://play.google.com/store/apps/details?id=com.pockettranslator.english2any

I had originally learned python, and build the basics of the app, and was happy 
to see that sl4a existed, and went into free versions of the apps that required 
the download of the interpreter separately.  After 6 months of non-stop 
programming (obsession;), I realized that ad support with the free versions 
wasn't feasible, as I haven't got a handle on integrating AdMob sdk.. plus I 
realized to charge a premium, having to download the interpreter separately 
scares most buyers away (even at $0.99!)  So I put the time in to incorporate 
the embedded interpreter.  I recommend doing this, though I had to relearn 
eclipse all over again (I'm not much of a java nut yet), in the end we have a 
complete product, and I'm sure any python programmer would agree, now with 
Python, we can do ANYTHING!

Awesome Sauce;)

M. Dave Cote B.Sc., B.A.Sc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Understanding http proxies

2012-10-15 Thread Olive
Thank you for all yours answers. There are very usefull!

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