Re: sqlalchemy beginner

2011-11-21 Thread Cameron Simpson
On 21Nov2011 22:18, Roy Smith  wrote:
| In article 
| <8832ab6d-8def-45d1-92df-baac40e1c...@t36g2000prt.googlegroups.com>,
|  alex23  wrote:
| > On Nov 22, 10:25?am, Roy Smith  wrote:
| > > Everytime I've worked with SQLAlchemy, I've run away screaming in the
| > > other direction. ?Sure, portability is a good thing, but at what cost?
| > 
| > I've never found SQLAlchemy to be anything but sane and approachable.
| > It's really worth understanding _how_ it works so you can see there's
| > no magic happening there.
| > 
| > What cost do you see inherit in the use of SQLAlchemy?
| 
| The cost of understanding how it works :-)
| 
| Seriously.  I understand SQL.  Well, I'm not a SQL wizard, but I 
| understand enough to do what I need to do.  Whenever I have to use 
| SQLAlchemy, I always find myself knowing exactly what SQL I want to 
| write and scratching my head to figure out how to translate that into 
| SQLAlchemy calls.

Are you trying to go the ORM route (make classes etc mapping to SQL
entities etc)?

I ask because I avoid ORM and mostly use the SQL syntax notation, eg:

for node_id, attr, value in select( [ attrs.c.NODE_ID,
  attrs.c.ATTR,
  attrs.c.VALUE,
] ) \
.order_by(asc(attrs.c.NODE_ID)) \
.execute():

or:

self.attrs.delete(self.attrs.c.NODE_ID == node_id).execute()

which I find very easy to read (self.attrs is an SQLAchemy table).

ORMs seem very cool and all, but I personally prefer to work with simple
SQL level schemae and python-level objects and classes i.e. not ORM
classes but ordinary classes that cll SQLAlchemy
select/update/delete/etc methods to manipulate the db.

For me the great strengths of SQLA are that it (1) talks to many
different backend DBs and (2) removes the need to write tediously quotes
SQL because I can write python expressions like the above that map
directly to SQL statements, and SQLA does all the quoting, conversion
etc. Reliably!

Cheers,
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

I sometimes wish that people would put a little more emphasis upon the
observance of the law than they do upon its enforcement. - Calvin Coolidge
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: decorators and closures

2011-11-21 Thread Steven D'Aprano
On Mon, 21 Nov 2011 14:44:34 +, Andrea Crotti wrote:

> With one colleague I discovered that the decorator code is always
> executed, every time I call a nested function:

"def" is a statement which is executed at runtime. Often people will talk 
about "definition time" instead of "compile time".

Python compiles your source into byte code (compile time), then executes 
the byte code. The function doesn't actually get created until the byte 
code is executed, i.e. at run time. This is not as slow as it sounds, 
because the function is created from pre-compiled parts.

In effect, if you have a module:

x = 23
def spam(a):
print x
print x+1
return x**3


then the body of the function is compiled into a "code object" at compile 
time, and at runtime the function object itself is assembled from the 
code object, name, and whatever other bits and pieces are needed. In 
pseudo-code, the byte code looks like this:

bind name "x" to object 23
build a function object "spam" from code object
bind name "spam" to function object

The hard part is creating the code object, as that requires parsing the 
source code of the body and generating byte code. That's done once, ahead 
of time, so the actual "build a function" part is fast.

Now, if you have an ordinary nested function:

def spam(a):
def ham(b):
return a+b
return ham(a+42)  # returns a numeric value

or a closure:

def spam(a):
def ham(b):
return a+b
return ham  # returns a closure (function object)

the process is no different: the inner function doesn't get created until 
runtime, that is, when spam gets *called*. But it gets created from parts 
that were prepared earlier at compile time, and so is fast.

Add a decorator, and the basic process remains. Remember that decorator 
syntax is just syntactic sugar. This:

@decorator
def spam():
pass

is exactly the same as this:

def spam():
pass

spam = decorator(spam)

which clearly has to be done at runtime, not compile time. That applies 
regardless of whether the function is nested or top-level.



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


Re: sqlalchemy beginner

2011-11-21 Thread Roy Smith
In article 
<8832ab6d-8def-45d1-92df-baac40e1c...@t36g2000prt.googlegroups.com>,
 alex23  wrote:

> On Nov 22, 10:25 am, Roy Smith  wrote:
> > Everytime I've worked with SQLAlchemy, I've run away screaming in the
> > other direction.  Sure, portability is a good thing, but at what cost?
> 
> I've never found SQLAlchemy to be anything but sane and approachable.
> It's really worth understanding _how_ it works so you can see there's
> no magic happening there.
> 
> What cost do you see inherit in the use of SQLAlchemy?

The cost of understanding how it works :-)

Seriously.  I understand SQL.  Well, I'm not a SQL wizard, but I 
understand enough to do what I need to do.  Whenever I have to use 
SQLAlchemy, I always find myself knowing exactly what SQL I want to 
write and scratching my head to figure out how to translate that into 
SQLAlchemy calls.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interesting problem about uuid1

2011-11-21 Thread alex23
On Nov 21, 5:33 pm, sword  wrote:
> My colleague asks me an interesting problem about uuid library in
> python. In multicore system with multiprocessing, is it possible to
> get the duplicated uuid with uuid1?
>
> I just check the RFC 4122, and I can't find anything about multicore
> environment. Python's uuid1 method generates the uuid with time stamp,
> mac address, and algorithm to gen random numbers. So, I think it's
> possible to get the duplicate uuid1 at the same time.
>
> What about you? Hope for your reply

Check the library documentation: http://docs.python.org/library/uuid.html

uuid.uuid1([node[, clock_seq]])
Generate a UUID from a host ID, sequence number, and the current time.
If node is not given, getnode() is used to obtain the hardware
address. If clock_seq is given, it is used as the sequence number;
otherwise a random 14-bit sequence number is chosen.

Each process would have to not only execute at the exact same time, it
would have to generate the same 14-bit random sequence. And if you're
really concerned, try specifying a different clock_seq for each core.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there any way to unimport a library

2011-11-21 Thread DevPlayer
On Nov 20, 12:21 pm, Gelonida N  wrote:
> I forgot to mention, that this is at the moment more a thought
> experiment, than a real need.
>
> At the moment I will do exactly what you suggested. I will make sure,
> that always the first import fails.
>
> But I wanted to learn more what is possible and which potential can of
> worms I would open if I wanted to unimport a library of which I'm sure
> that nobody is currently referencing (or refering? Not sure about my
> English here) to.

Get how many references to an object:
sys.getrefcount(sys)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple Threads - I/O in Same File

2011-11-21 Thread James Matthews
You may have some issues with disk reading as the drive heads move in
different ways

On Mon, Nov 21, 2011 at 8:15 AM,  wrote:

> Hi All,
>
> ** **
>
> Just a question in general.  Is it possible that we have opened one file
> in r+ mode ( file1.txt ). 
>
> We have 2 threads, 
>
> **· **Thread1 will continuously ‘only read’ the file in a loop. **
> **
>
> **· **Thread2 will only update the data in the file ( say a
> number < 100 ). 
>
> Now thread2 has called other script ( written in say Perl/Powershell using
> subprocess.call() ) and those scripts are inturn updating ( only writing )
> into that file by their own file i/o mechanism.
>
> ** **
>
> Is it possible by any chance? One file being shared between different
> processes one is only updating and other is only reading ..? Will this work
> in practical and what can be the complications ?
>
> ** **
>
> ** **
>
> Thanks
>
> Nikunj
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
http://www.goldwatches.com

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


Re: How to Get Data from DictReader for CSV Files

2011-11-21 Thread ray
On Nov 21, 10:29 am, GZ  wrote:
> Hi,
>
> On Nov 21, 7:42 am, ray  wrote:
>
>
>
>
>
> > I don't see how to get my data from the output.  I can see the data in
> > the rows but it is mixed in with the field names.  That is, the data I
> > get comes out as:
> > fieldname1 : data1 , fieldname2 : data2 , etc.
>
> > import csv
> > linelist=open( "C:/Users/me/line_list_r0.csv", "rb" )
> > csvReader= csv.DictReader( linelist, dialect='excel' )
> > for data in csvReader:
> >         print data
> > linelist.close()
>
> > I want to pass this data as arrays or lists to another module such as:
> > myfunction(data1, data2, data3)
>
> > How do I get the data I want out of the pair fieldname1 : data1?
>
> > Thanks,
> > ray
>
> It returns a dict(). You can reference the fields with
> data['fieldname1'], etc.- Hide quoted text -
>
> - Show quoted text -

GZ,

That works great.

Thanks,
ray
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What I do and do not know about installing Python on Win 7 with regard to IDLE.

2011-11-21 Thread alex23
"W. eWatson"  wrote:
> Comments?

Please don't start multiple threads on the same issue.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: JSONBOT 0.80.3 RELEASED

2011-11-21 Thread James Matthews
Looks good I am going to plug twisted into this.

On Mon, Nov 21, 2011 at 9:49 PM, Bart Thate  wrote:

> Hello world !! I released JSONBOT 0.80.3 .. the first in the 0.80 series ;]
>
> about
> ~
>
> JSONBOT is a chatbot that can take commands and react to events on the
> network it is connected to (IRC, XMPP, WEB
> mostely). Push functionality is also provided (think RSS feeds to your IRC
> channel or XMPP conference). It is possible to program your own plugins to
> create custom
> functionality.
>
> source/docs
> ~~~
>
>  see http://jsonbot.org and http://jsonbot.googlecode.com
>
>
> make backup first
> ~
>
> I added the jsb-backup program, please run this before starting the 0.80
> bot. It will make a backup of your datadir into ~/jsb-backups
>
> changes
> ~~~
>
> * GAE is no longer part of the standard distribution, as that is aimed at
> shell users as of 0.80 - use the mercurial repo if you want to use the GAE
> part of the bot
> * web console is now supported on shell - use the jsb-tornado program to
> launch a tornado web server bot on port 10102
> * jsb-xmpp now supports OpenFire - use --openfire option to enable this
> * todo now uses per user databases instead of per channel - use the -c
> option to the todo command to show the channel todo
> * learn items are not global per default - use !learn-toglobal to copy
> local learn data to the global learndb
> * relay plugins has been rewritten to use bot.cfg.name as well - means
> that relays need to be created again
> * jsb-udpstripped program has been added that can be used to send udp data
> to the bot without the need of making config files (copy and edit it)
> * add fulljids = 1 to your xmpp bot config (most of the times in
> ~/.jsb/config/fleet/default-sxmpp/config) to enable full JID discovery in
> xmpp conference rooms
>  (non anonymous)
>
> and:
>
> * lots of new plugins .. see !list ;]
> * lots of bug fixes - thnx everybody for reporting them
> * still lots of things to fix at
>
> 03:35 < jsonbot> tracker is http://code.google.com/p/jsonbot/issues/list
>
> If you find any problems or have feature request please post that on the
> tracker url above.
>
> Or try @botfather on #dunkbots on irc.freenode.net ;]
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://www.goldwatches.com

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


Re: sqlalchemy beginner

2011-11-21 Thread alex23
On Nov 22, 10:25 am, Roy Smith  wrote:
> Everytime I've worked with SQLAlchemy, I've run away screaming in the
> other direction.  Sure, portability is a good thing, but at what cost?

I've never found SQLAlchemy to be anything but sane and approachable.
It's really worth understanding _how_ it works so you can see there's
no magic happening there.

What cost do you see inherit in the use of SQLAlchemy?
-- 
http://mail.python.org/mailman/listinfo/python-list


JSONBOT 0.80.3 RELEASED

2011-11-21 Thread Bart Thate
Hello world !! I released JSONBOT 0.80.3 .. the first in the 0.80 series ;]

about
~

JSONBOT is a chatbot that can take commands and react to events on the network 
it is connected to (IRC, XMPP, WEB
mostely). Push functionality is also provided (think RSS feeds to your IRC 
channel or XMPP conference). It is possible to program your own plugins to 
create custom
functionality. 

source/docs
~~~

 see http://jsonbot.org and http://jsonbot.googlecode.com


make backup first
~

I added the jsb-backup program, please run this before starting the 0.80 bot. 
It will make a backup of your datadir into ~/jsb-backups

changes
~~~

* GAE is no longer part of the standard distribution, as that is aimed at shell 
users as of 0.80 - use the mercurial repo if you want to use the GAE part of 
the bot
* web console is now supported on shell - use the jsb-tornado program to launch 
a tornado web server bot on port 10102 
* jsb-xmpp now supports OpenFire - use --openfire option to enable this
* todo now uses per user databases instead of per channel - use the -c option 
to the todo command to show the channel todo
* learn items are not global per default - use !learn-toglobal to copy local 
learn data to the global learndb
* relay plugins has been rewritten to use bot.cfg.name as well - means that 
relays need to be created again  
* jsb-udpstripped program has been added that can be used to send udp data to 
the bot without the need of making config files (copy and edit it)
* add fulljids = 1 to your xmpp bot config (most of the times in 
~/.jsb/config/fleet/default-sxmpp/config) to enable full JID discovery in xmpp 
conference rooms
  (non anonymous)

and:

* lots of new plugins .. see !list ;]
* lots of bug fixes - thnx everybody for reporting them
* still lots of things to fix at 

03:35 < jsonbot> tracker is http://code.google.com/p/jsonbot/issues/list

If you find any problems or have feature request please post that on the 
tracker url above.

Or try @botfather on #dunkbots on irc.freenode.net ;]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mask one array using another array

2011-11-21 Thread questions anon
thank you, that makes sense.
 I should have posted this on another list (which I have now). and the
change required is:

If your new array is x, you can use:

numpy.ma.masked_array(x, mask=mask.mask)

On Tue, Nov 22, 2011 at 11:48 AM, MRAB  wrote:

> On 21/11/2011 21:42, questions anon wrote:
>
>> I am trying to mask one array using another array.
>>
>> I have created a masked array using
>> mask=MA.masked_equal(myarray,**0),
>> that looks something like:
>> [1  -  -  1,
>>  1  1  -  1,
>>  1  1  1  1,
>>  -   1  -  1]
>>
>> I have an array of values that I want to mask whereever my mask has a a
>> '-'.
>> how do I do this?
>> I have looked at
>> http://www.cawcr.gov.au/bmrc/**climdyn/staff/lih/pubs/docs/**masks.pdfbut
>> the command:
>>
>> d = array(a, mask=c.mask()
>>
>> results in this error:
>> TypeError: 'numpy.ndarray' object is not callable
>>
>> I basically want to do exactly what that article does in that equation.
>>
>> Any feedback will be greatly appreciated.
>>
>>  The article is using the Numeric module, but your error says that you're
> using
> the numpy module. They're not the same.
> --
> http://mail.python.org/**mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mask one array using another array

2011-11-21 Thread MRAB

On 21/11/2011 21:42, questions anon wrote:

I am trying to mask one array using another array.

I have created a masked array using
mask=MA.masked_equal(myarray,0),
that looks something like:
[1  -  -  1,
  1  1  -  1,
  1  1  1  1,
  -   1  -  1]

I have an array of values that I want to mask whereever my mask has a a '-'.
how do I do this?
I have looked at
http://www.cawcr.gov.au/bmrc/climdyn/staff/lih/pubs/docs/masks.pdf but
the command:

d = array(a, mask=c.mask()

results in this error:
TypeError: 'numpy.ndarray' object is not callable

I basically want to do exactly what that article does in that equation.

Any feedback will be greatly appreciated.

The article is using the Numeric module, but your error says that you're 
using

the numpy module. They're not the same.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Non-POSIX parity (mark/space) with Python-Serial on Linux.

2011-11-21 Thread Chris Angelico
On Tue, Nov 22, 2011 at 10:09 AM, Grant Edwards  wrote:
> On 2011-11-21, Grant Edwards  wrote:
>
>> Like the old joke:
>>
>>   There are 10 kinds of people in the world: those who understand
>>   binary numbers, and those who don't.
>
> OK, it's not _much_ of a joke, but I don't get to use it very often,
> so I couldn't let it go (for one thing, it only works in "print").

On a scale of 1 to 10, what is the probability that this is in binary?

There's plenty of great binary jokes going around.

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


Re: sqlalchemy beginner

2011-11-21 Thread Roy Smith
In article ,
 Jabba Laci  wrote:

> Hi,
> 
> I'm reading the Essential SQLAlchemy book from O'Reilly.

Everytime I've worked with SQLAlchemy, I've run away screaming in the 
other direction.  Sure, portability is a good thing, but at what cost?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using the Python Interpreter as a Reference

2011-11-21 Thread Travis Parks
On Nov 21, 12:44 am, Steven D'Aprano  wrote:
> On Mon, 21 Nov 2011 13:33:21 +1100, Chris Angelico wrote:
> > What's your language's "special feature"? I like to keep track of
> > languages using a "slug" - a simple one-sentence (or less) statement of
> > when it's right to use this language above others. For example, Python
> > is optimized for 'rapid deployment'.
>
> "Python will save the world"
>
> http://proyectojuanchacon.blogspot.com/2010/07/saving-world-with-pyth...
>
> --
> Steven

The language, psuedo name Unit, will be a low-level language capable
of replacing C in most contexts. However, it will have integrated
functional programming features (tail-end recursion optimization,
tuples, currying, closures, function objects, etc.) and dynamic
features (prototypical inheritance and late binding).

It is a hybrid between C#, C++, F#, Python and JavaScript. The hope is
that you won't pay for features you don't use, so it will run well on
embedded devices as well as on desktops - that's to be seen. I'm no
master compiler builder, here.

The functional code is pretty basic:

let multiply = function x y: return x * y # automatic generic
arguments (integer here)
let double = multiply _ 2 # short-hand currying - inlined if possible
let doubled = [|0..10|].Apply(double) # double zero through 10

The dynamic code is pretty simple too:

dynamic Prototype = function value: self.Value = value # simulated
ctor
Prototype.Double = function: self.Value * 2 # self refers to instance
new Prototype(5).Double() # 10
new Prototype(6).Double() # 12
dynamic x = 5 # five wrapped with a bag
x.Double = function: self * 2
x.Double() # 10
dynamic y = 6
y.Double = x.Double # member sharing
y.Double() #12

The language also sports OOP features like are found in Java or C#:
single inheritance; multiple interface inheritance; sealed, virtual
and abstract types and members; explicit inheritance; extension
methods and namespaces.

The coolest feature will be its generics-oriented function signatures.
By default everything is generic. You apply constraints to parameters,
rather than specific types. For instance:

let Average = function values:
where values is ICountable IIterable
assert values.Count > 0 "The values list cannot be empty."
throws ArgumentException
returns Float64
let sum = 0
for value in values:
sum += value
return sum / values.Count # floating point division

As you can see, the function headers can be larger than the bodies
themselves. They support type constraints, assertions (argument
checking), exceptions enumeration, default parameters and return type
information. All of them can be left out if the type of arguments can
be inferred.

This will not be an overnight project. :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Peculiarity of '@' in logging.Formatter

2011-11-21 Thread Charlie Martin
Oops, forgot the python version etc:

bash $ /usr/bin/env python -V
Python 2.7

On SuSE 11.4

bash $ uname -a
Linux crmartin 2.6.37.6-0.9-desktop #1 SMP PREEMPT 2011-10-19 22:33:27 +0200 
x86_64 x86_64 x86_64 GNU/Linux
-- 
http://mail.python.org/mailman/listinfo/python-list


Peculiarity of '@' in logging.Formatter

2011-11-21 Thread Charlie Martin
This is what seems like an odd bug, but in code I'd thing often-enough used it 
must be the expected behavior and I just don't understand.  Please, 
sirs/mesdames, is this a bug?

Example code:
 begin code ---
#!/usr/bin/env python

"""
@-character WTF?
"""
import sys
import os
import logging, logging.handlers
import socket

log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)

fmtColon = logging.Formatter('[%(module)s:%(lineno)03d]:%(message)s')
strC = logging.handlers.SysLogHandler(address='/dev/log')
strC.setFormatter(fmtColon)
strC.setLevel(logging.DEBUG)
log.addHandler(strC)

fmtAt = logging.Formatter('[%(module)s@%(lineno)03d]:%(message)s')
strA = logging.handlers.SysLogHandler(address='/dev/log')
strA.setFormatter(fmtAt)
strA.setLevel(logging.DEBUG)
log.addHandler(strA)

log.info("My log message:isn't it special?")
 end code 

produces these entries in the syslog messages:

 begin results --
Nov 21 16:09:56 crmartin [atSign: 026]:My log message:isn't it special?
Nov 21 16:09:56 crmartin [atSign@026]: My log message:isn't it special?
 end results 

Observe: 

* in the first entry, "[atSign: 026]:My" with space after the first ":"; that 
space isn't in the format string.

* in the second entry "[atSign@026]: My" again has an additional space after 
the first ":"

the colons following are unchanged.

This **seems** like it must be some obscure bug, but perhaps it's some 
undocumented feature?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Non-POSIX parity (mark/space) with Python-Serial on Linux.

2011-11-21 Thread Grant Edwards
On 2011-11-21, Grant Edwards  wrote:

> Like the old joke:
>
>   There are 10 kinds of people in the world: those who understand
>   binary numbers, and those who don't.

OK, it's not _much_ of a joke, but I don't get to use it very often,
so I couldn't let it go (for one thing, it only works in "print").


-- 
Grant Edwards   grant.b.edwardsYow! I feel like I am
  at   sharing a ``CORN-DOG''
  gmail.comwith NIKITA KHRUSCHEV ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Non-POSIX parity (mark/space) with Python-Serial on Linux.

2011-11-21 Thread Grant Edwards
On 2011-11-21, David Riley  wrote:
> On Nov 21, 2011, at 2:29 PM, Matthew Lenz wrote:
>
>> Another thing I noticed is that the & and | appear to give the same result 
>> as adding or subtracting 128 from the ordinal value.  I'm assuming that 
>> isn't coincidence. :)
>
> It's not, though the difference is important.  They're binary ANDs (&) and 
> ORs (|), so (0x0F | 0x80) = 0x8F, but (0x8F | 0x80) = 0x8F as well, whereas 
> (0x8F + 0x80) = 0x10F.  For manipulating bit values (which is what you're 
> doing, you should almost never be adding or subtracting, but rather ANDing 
> and ORing (or XORing, but not nearly as often).
>
> Just in case you're not familiar, 0x is the prefix for a hexadecimal number. 
> 0x80 = 128, which is binary 1000 (i.e. the high bit in a byte).

Like the old joke:

  There are 10 kinds of people in the world: those who understand
  binary numbers, and those who don't.

-- 
Grant Edwards   grant.b.edwardsYow! ... I don't like FRANK
  at   SINATRA or his CHILDREN.
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What I do and do not know about installing Python on Win 7 with regard to IDLE.

2011-11-21 Thread Terry Reedy

On 11/21/2011 11:39 AM, W. eWatson wrote:


My criterion for success is that it puts IDLE as a choice for editor on
the menu produced with a right-click on a py file.


Your first criterion for success should be that IDLE runs at all, which 
is apparently does not. How you run it is secondary.


Right-click responses are controlled by Windows using data in the 
registry. Windows modifies the registry in response to installers *and 
users*. The ActiveState installers request 'Edit with PythonWin'. They 
do not request 'Edit with IDLE' and it is foolish to complain to us when 
you use ActiveState and get their choice of context choices.


The PSF .msi installers (.msi = MicroSoftInstall format) from python.org 
request 'Edit with IDLE' but cannot make Windows put it in. If your 
registry is messed up enough, it does not happen. But no error message.


I have explained to you another way to work with IDLE once it runs. It 
you refuse to use it, that is your problem, not ours.



I know it sets up that way on a 2.5 and 2.4 on other PCs I have.


You installed with the PSF installer with an ok registry.


I know at one time it worked on my 64-bit Win 7 PC, which likely had a
32-bit version installed on it. After something like six months of
modest use it stopped working as above. No IDLE choice.


So some *other* program messed things up. Stop blaming us.
Heavy or modest use in the meantime is irrelevant.


I know by installing a 64-bit version, 3.2.2 failed the IDLE criterions
as described. No IDLE.


Did you uninstall the 32 bit version, and best, all Python versions?


I do know that IDLE appears on the Win 7 Start menu, but, when used,
nothing happens. Well, OK, for about 3 seconds the Win 7 "working" icon
spins around then zip, nothing.


This is your real problem. Stop worrying about the context menu.

> Further, right-clicking on Properties of

IDLE (GUI) produces a tabbed dialog. It shows Start in: c:\Python32\,


This is the Shortcut tab. A shortcut is like a bound method. The 
function is the target: 'python 3.2.2 (64 bit)' on my machine. The 
starting directory is like a bound argument, although it is passed to 
the launcher that launches the function. What the Properties dialog does 
not show are the actual 'bound arguments' that are passed to the target 
as options. So one cannot know what the shortcut is actually trying to 
do. This is one of the Really Stupid things about Windows that should 
have been fixed long ago but has not.



and None for shortcut.


None for Shortcut key, such as alt-I to invoke the shortcut.


There is a compatibility tab, which I've set to
Win7. I think there's a troubleshooter there too, but I haven't used it.
Under the Details tab, it shows Name: IDLE(Python Gui).lnk. Folder Path
as: c:\ProgramData\Microsoft\Windows\Start... Nothing after the "...".


Details: Folder Path is the same as General: Location. Mouse over the 
latter the the full path appears. That Properties windows are still 
fixed at 480 pixel wide, regardless of screen size, is another Really 
Stupid thing.



Going directly to ...\Lib\idlelib\idle.pyw produces the spinning icon.
At least, that's what happens in 3.2.2, but in the 32-bit versions I
tried, I would get "invalid Win 32 app".


If the registry entry for .pyw is messed up, trying to run the file by 
clicking on it is not likely to work. Try running from Command Prompt, 
as I believe others suggested.



When I rebooted my system a few hours after installing 3.2.2, because
the PC was running really slowly--not because of Python, I was greeted
by a couple of interesting messages as the desktop was populated.

I can execute Python from the command line.

1. Specified module could not be found: Load Lib, python.dll.

2. \ProgramFiles(x86)\uniblueDrivers\Scanner (x86) Python26.dll.


The uniblue drivers program will match your drivers against a database 
of up-to-date drivers and offer to upgrade them. I have used uniblue's 
registry scanner program. Treating pythonxy.dll as a driver, if they 
are, is an error. These are paid programs. The free demos only scan to 
tell you what they would do if you bought them.


> I'm sure this is related to Winamp, which I had installed a month ago.

I do not believe they are the same companies, but they may have a 
cross-promotion deal.



had some "crazy" choice to scan for new drivers. Of course, if it found
one-connected with Python, and if you wanted it, $$$. I think this
message is a red herring. I may re-install Winamp to get rid of that
uniblue tool that seems like nothing more than an ad.

Some have suggested a registry problem, but I don't have a clue how to
play with that, or somehow clean it up, if there is a problem. My PC
behaves normally


If you ran the psf 3.2.2 installer and idle does not run when you click 
the start menu shortcut, something is wrong.



Someone suggested using the mail list at
. What's different
about that list than this N

Re: Both Python 2.5.2 and 2.7.2 flop the same way under Win 7

2011-11-21 Thread Alan Meyer

On 11/17/2011 3:43 PM, Chris Angelico wrote:

...
If you're having issues, grab a spare computer, throw Linux on it (I
recommend Ubuntu or Debian, others will have other preferred distros),
and see if the issues remain. Or if you're having trouble with the
GUI, try things from the command line (Windows's command interpreter
is pretty weak compared to bash, but it's plenty powerful enough).

ChrisA


If the OP is having trouble with this issue, and if he can't make 
Windows work here, I suspect that he'll get into trouble trying to 
install and test with Linux.


However if he did want to try it, and assuming he's got 8GB or so of 
extra space, one easy way to test with Linux is to install VirtualBox, 
then install Linux under that.  I've done that a half dozen times 
without hiccups.  That way he doesn't need a second machine and doesn't 
need to repartition or toss his old OS.


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


Re: Close as Many Files/External resourcs as possible in the face of exceptions

2011-11-21 Thread Terry Reedy

On 11/21/2011 7:09 AM, Mel Wilson wrote:

GZ wrote:

Here is my situation. A parent object owns a list of files (or other
objects with a close() method). The close() method can sometimes fail
and raise an exception. When the parent object's close() method is
called, it needs to close down as many files it owns as possible, even
if the close() function of some files fail. I also want to re-raise at
least one of the original exceptions so that the outer program can
handle it.

[ ... ]


It will re-raise the first exception and preserve the context and
close as many other files as possible while ignoring any further
exceptions.

But this looks really awkward. And in the case that two files fail to
close, I am not sure the best strategy is to ignore the second failure.


I imagine you could save any caught exception instances in a list and
study them later.


Yes, I would raise a custom exception instance that takes such a list of 
failures in its constructor. Give it a custom __str__ method to display 
them all.


--
Terry Jan Reedy

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


mask one array using another array

2011-11-21 Thread questions anon
I am trying to mask one array using another array.

I have created a masked array using
mask=MA.masked_equal(myarray,0),
that looks something like:
[1  -  -  1,
 1  1  -  1,
 1  1  1  1,
 -   1  -  1]

I have an array of values that I want to mask whereever my mask has a a '-'.
how do I do this?
I have looked at
http://www.cawcr.gov.au/bmrc/climdyn/staff/lih/pubs/docs/masks.pdf but the
command:

d = array(a, mask=c.mask()

results in this error:
TypeError: 'numpy.ndarray' object is not callable

I basically want to do exactly what that article does in that equation.

Any feedback will be greatly appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: youtube-dl: way to deal with the size cap issue + new errors + issues ...

2011-11-21 Thread Philipp Hagemeister
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

As a general rule, feel free to contact youtube-dl developers and users
at https://github.com/rg3/youtube-dl/issues/ . youtube-dl is just one
application, which happens to be written in Python.

l...@mail.python.org wrote:
>  I did find my way (through a silly hack) to get all files within a size 
> range without waiting for youtube-dl to be "enhanced".
You may be able to send a HEAD request to the URL, but there's no
guarantee the response will contain a Content-Length header. In fact,
there will never be a Content-Lenght header for infinite HTTP streams.
Also, RTMP URLs are way more complicated.

>  I have also been getting errors reporting:
>  RTMP download detected but "rtmpdump" could not be run
You need rtmpdump. See http://rtmpdump.mplayerhq.hu/ for instructions on
how to install it.

>  It would be very helpful if you could redirect youtube-dl errors to a 
> separate file you would indicate via a flag
If you think so, please open an issue. Do not forget to consider the
usefulness not only for your specific application, but also of other
applications. I think the command-line API
(https://github.com/rg3/youtube-dl/issues/152) will be your best shot.
Note that you can already redirect youtube-dl's output to a file, just
like any other shell program:

$ youtube-dl uHlDtZ6Oc3s > log

will write a file log that contains all of youtube-dl's output. If the
return code is not 0, an error has occured.

Cheers,

Philipp
youtube-dl developer
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (GNU/Linux)

iEYEAREKAAYFAk7KvygACgkQ9eq1gvr7CFw6GwCfeaF0TPNonTCaXVBDnmDBPio2
qVQAn2/JQzTbBYs+pe50t4qVCjxY+BLy
=o6uC
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Non-POSIX parity (mark/space) with Python-Serial on Linux.

2011-11-21 Thread David Riley
On Nov 21, 2011, at 2:29 PM, Matthew Lenz wrote:

> Another thing I noticed is that the & and | appear to give the same result as 
> adding or subtracting 128 from the ordinal value.  I'm assuming that isn't 
> coincidence. :)

It's not, though the difference is important.  They're binary ANDs (&) and ORs 
(|), so (0x0F | 0x80) = 0x8F, but (0x8F | 0x80) = 0x8F as well, whereas (0x8F + 
0x80) = 0x10F.  For manipulating bit values (which is what you're doing, you 
should almost never be adding or subtracting, but rather ANDing and ORing (or 
XORing, but not nearly as often).

Just in case you're not familiar, 0x is the prefix for a hexadecimal number. 
0x80 = 128, which is binary 1000 (i.e. the high bit in a byte).


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


SetStatusText of MDIParentFrame from MDIChildFrame

2011-11-21 Thread Illy

Dear my friends

I am stucked on a problem: I can't call a function of MDIParentFrame 
from MDIChildFrame: myturnonmenu and mystatusbar.SetStatusText()


Anybody would be so nice for telling me my mistakes? Please do me a favor.

Thank you very much in advance.

I created 3 files contain this sourcecode:
ceo@mefi:~/sementara/tes$ ls
jendelapos.py  jendelapos.pyc  myMDIChildFrameforLogin.py  
myMDIChildFrameforLogin.pyc  myMDIFrame.py

ceo@mefi:~/sementara/tes$
===
ceo@mefi:~/sementara/tes$ cat myMDIFrame.py
#!/usr/bin/env python
import wx
import os

import jendelapos
import myMDIChildFrameforLogin

class myMDIParentFrame (wx.MDIParentFrame):
def __init__(self):
global mystatusbar, menuakuntan

wx.MDIParentFrame.__init__(self, None, -1, "This is 
myMDIParentFrame", size=(1020,800))

mystatusbar = self.CreateStatusBar()
mystatusbar.SetStatusText("This is the StatusBar I want to put 
my message for the users in it")

menuakuntan = wx.Menu()
menuakuntan.Append(1000,  "Accounting - POS (&Point of Sale)")

menuaplikasi = wx.Menu()
menuaplikasi.Append(2,  "&Login")
menuaplikasi.Append(20001,  "E&xit")

menubar = wx.MenuBar()
menubar.Append(menuakuntan,  "&Accounting")
menubar.Append(menuaplikasi,  "A&pplication")
myturnoffmenu(self)

self.SetMenuBar(menubar)

self.Bind (wx.EVT_MENU,  self.jendelapos,  id=1000)

self.Bind (wx.EVT_MENU,  self.myMDIChildFrameforLogin,  id=2)
self.Bind (wx.EVT_MENU,  self.OnExit,  id=20001)

def OnExit(self,  evt):
self.Close(True)

jendelapos =  jendelapos.Show

myMDIChildFrameforLogin = myMDIChildFrameforLogin.Show

def myturnoffmenu(self):
menuakuntan.Enable(1000, False)

def myturnonmenu(self):
menuakuntan.Enable(1000, True)

if __name__ == '__main__':
app = wx.PySimpleApp()
myMDIFrame = myMDIParentFrame()
myMDIFrame.Show()
app.MainLoop()
ceo@mefi:~/sementara/tes$
=
ceo@mefi:~/sementara/tes$ cat ./myMDIChildFrameforLogin.py
import wx

def Show(self, evt):
global pengguna, katakunci, jendela
jendela = wx.MDIChildFrame(self, -1, "Login Form",  style= 
wx.DEFAULT_FRAME_STYLE | wx.HSCROLL | wx.VSCROLL)


mystatusbar.SetStatusText("Login succeeded")
myturnonmenu()

jendela.Show(True)
ceo@mefi:~/sementara/tes$
=
ceo@mefi:~/sementara/tes$ cat jendelapos.py
import wx

def Show (self, evt):
win = wx.MDIChildFrame(self, -1,  "Accounting - POS")
win.Show(True)
ceo@mefi:~/sementara/tes$
=

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


Re: Non-POSIX parity (mark/space) with Python-Serial on Linux.

2011-11-21 Thread Grant Edwards
On 2011-11-21, Matthew Lenz  wrote:

> Another thing I noticed is that the & and | appear to give the same
> result as adding or subtracting 128 from the ordinal value.

Nope, that's only true for some values.

If we're limiting ourselves to byte values, then we're talking
modulo-256 arithmetic, so:

128 + 128 = 0 
128 | 128 = 128

0 - 128  = 128
0 & 0x7f = 0


What's is true is that adding 128 is actullay the same as subtracting
128, and both are the same as exclusive-or 128 (v ^ 128):

>>> x = 128
>>> (x + 128) & 0xff
0
>>> (x - 128) & 0xff
0
>>> (x ^ 128) & 0xff
0

>>> x = 0
>>> (x + 128) & 0xff
128
>>> (x - 128) & 0xff
128
>>> (x ^ 128) & 0xff
128

> I'm assuming that isn't coincidence. :)

Well, the weighting of the high-order bit in an 8-bit wide binary
number is 128, if that's what you're getting at...

-- 
Grant Edwards   grant.b.edwardsYow! How's it going in
  at   those MODULAR LOVE UNITS??
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Non-POSIX parity (mark/space) with Python-Serial on Linux.

2011-11-21 Thread Matthew Lenz
Another thing I noticed is that the & and | appear to give the same result as 
adding or subtracting 128 from the ordinal value.  I'm assuming that isn't 
coincidence. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to: Coordinate DictReader and Reader for CSV

2011-11-21 Thread Tim Chase

On 11/21/11 09:16, ray wrote:

Is there a way to capture the keys outside of the for loop so
when the for loop is entered, only data is extracted?


I frequently do this for things like tweaking headers (stripping 
space, normalizing case, etc because clients love to send us 
messy data):


  def norm_header(h):
return h.strip().upper()
  def norm_item(i):
return i.strip()

  f = file("example.csv", "rb")
  try:
r = csv.reader(f)
headers = r.next()
header_map = dict(
  (norm_header(h), i)
  for i, h in enumerate(headers)
  )
for row in r:
  item = lambda h: norm_item(row[header_map[norm_header(h)]])
  value1 = item("Item1")
  value2 = item("ITEM3")
  ...
  finally:
f.close()

Should work in 2.x, possibly in 3.x (though you might need to 
change from "headers = r.next()" to "headers = next(r)")


-tkc


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


[ANN] json_diff 0.9.2 released - JSON files comparator

2011-11-21 Thread Matěj Cepl

I released json_diff 0.9.2.
http://pypi.python.org/pypi/json_diff

json_diff is an utility comparing two JSON files and generating diff in 
form of another JSON file with differences for each level of the object 
in a dict


{
   "_append": {},
   "_remove": {},
   "_update": {}
}

This is the first public release, working my way towards 1.0 release.

Development repository is at https://gitorious.org/json_diff, patches 
and pull requests welcome!


--
http://www.ceplovi.cz/matej/, Jabber: mceplceplovi.cz
GPG Finger: 89EF 4BC6 288A BF43 1BAB  25C3 E09F EF25 D964 84AC

Basically, the only “intuitive” interface is the nipple.  After
that, it's all learned.
-- Bruce Ediger when discussing intuivity of Mac OS
   http://groups.google.com/group/comp.sys.next.advocacy\
   /msg/7fa8c580900353d0

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


Re: SQLObject 1.2.0

2011-11-21 Thread Daniel Fetchinson
Thanks a million Oleg!

Cheers,
Daniel


On 11/20/11, Oleg Broytman  wrote:
> Hello!
>
> I'm pleased to announce version 1.2.0, the first stable release of branch
> 1.2 of SQLObject.
>
>
> What is SQLObject
> =
>
> SQLObject is an object-relational mapper.  Your database tables are
> described
> as classes, and rows are instances of those classes.  SQLObject is meant to
> be
> easy to use and quick to get started with.
>
> SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite,
> Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB).
>
>
> Where is SQLObject
> ==
>
> Site:
> http://sqlobject.org
>
> Development:
> http://sqlobject.org/devel/
>
> Mailing list:
> https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss
>
> Archives:
> http://news.gmane.org/gmane.comp.python.sqlobject
>
> Download:
> http://pypi.python.org/pypi/SQLObject/1.2.0
>
> News and changes:
> http://sqlobject.org/News.html
>
>
> What's New
> ==
>
> Features & Interface
> 
>
> * Strings are treated specially in Select to allow
>   Select(['id, 'name'], where='value = 42'). Update allows a string in
>   WHERE.
>
> * ForeignKey('Table', refColumn='refcol_id') to allow ForeignKey to
>   point to a non-id column; the referred column must be a unique integer
>   column.
>
> * delColumn now accepts a ForeignKey's name without 'ID'.
>
> * Support for PostgreSQL 7.* is dropped. The minimal supported version of
>   PostgreSQL is 8.1 now.
>
> * Quoting rules changed for PostgreSQL: SQLObject uses E'' escape string
>   if the string contains characters escaped with backslash.
>
> * A bug caused by psycopg2 recently added a new boolean not callable
>   autocommit attribute was fixed.
>
> * sqlobject.__doc__ and main.__doc__ no longer contain version number.
>   Use sqlobject.version or version_info.
>
> For a more complete list, please see the news:
> http://sqlobject.org/News.html
>
> Oleg.
> --
>  Oleg Broytmanhttp://phdru.name/p...@phdru.name
>Programmers don't die, they just GOSUB without RETURN.
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Non-POSIX parity (mark/space) with Python-Serial on Linux.

2011-11-21 Thread gene heskett
On Monday, November 21, 2011 01:28:16 PM David Riley did opine:

> On Nov 21, 2011, at 12:25 PM, gene heskett wrote:
> > And that is 9600 baud 8n1 on both ends.  Ascii is normally 7 bit and
> > will have a low 8th bit if fed normal ascii data, so how is the 8th
> > bit getting set other than purposely setting 7M1 on the other end of
> > the cable?
> 
> That's what I thought the OP was doing; it sounds like he's trying to
> receive 7M1 in Minicom using 8N1 on the terminal and getting garbled
> data because the high bit is set (because the other end is sending
> 7M1).  I never meant to imply that 8N1 would give garbled data if both
> ends were set to it; indeed, that's pretty much standard communications
> settings for short cables in low to moderate noise environments.  If
> anyone else read it that way, that's not what I meant. :-)
> 
> - Dave

I think that getting the other end off 7M1 was what I was saying.  Trying 
to attack the bad data after capture by writing code always seems extremely 
masochistic to me.

The amount of miss-understanding that seems to pervade rs-232 
communications is mind boggling at times.  The tech itself is so old it is 
being forgotten!

Cheers, Gene
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
My web page: 
Whatever occurs from love is always beyond good and evil.
-- Friedrich Nietzsche
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Non-POSIX parity (mark/space) with Python-Serial on Linux.

2011-11-21 Thread MRAB

On 21/11/2011 16:52, Matthew Lenz wrote:

Ahh. Ok.  So how would I go about doing that with python?  I think in
perl (sorry for the naughty word) I could use the tr// (translate)
but is there a quick way to do so with python?  Is it going to be
necessary to convert commands I SEND to the device or only convert
what I receive?


Python strings have a .translate method:

# Example in Python 2
import string

# From top bit set...
from_chars = "".join(chr(c | 0x80) for c in range(0x7F))

# ...to top bit clear.
to_chars = "".join(chr(c) for c in range(0x7F))

# Build the translation table.
force_clear = string.maketrans(from_chars, to_chars)

s = "\x41\xC1"
print s
print s.translate(force_clear)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Non-POSIX parity (mark/space) with Python-Serial on Linux.

2011-11-21 Thread David Riley
On Nov 21, 2011, at 12:59 PM, Matthew Lenz wrote:

> Thanks, this will be a great help.
> 
> Just wanted to confirm that you meant to use [ .. for x in ord_str] in the 
> example conversion?  Got a TypeError using the received_str.

Yes, I probably should have double-checked that.  ord_str is indeed what I 
meant. :-)


- Dave


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


Re: Non-POSIX parity (mark/space) with Python-Serial on Linux.

2011-11-21 Thread Matthew Lenz
Thanks, this will be a great help.

Just wanted to confirm that you meant to use [ .. for x in ord_str] in the 
example conversion?  Got a TypeError using the received_str.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to Get Data from DictReader for CSV Files

2011-11-21 Thread Ian Kelly
The point of DictReader is that it produces dicts.  If you actually want a
sequence, then use an ordinary csv.reader instead.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What I do and do not know about installing Python on Win 7 with regard to IDLE.

2011-11-21 Thread Cousin Stanley
W. eWatson wrote:

> My criterion for success is that it puts IDLE as a choice for editor
> on the menu produced with a right-click on a py file. 
> 
> So far no response on this has solved the problem.
> 

  As an alternative you might consider adding a short-cut to IDLE 
  to the  Send To  directory if that option is still available
  under windows 7  

  That would seem  almost  as handy 
  only moving the mouse one more time
  to roll out the  Send To  target menu  
  before the final click to launch 


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

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


Re: Non-POSIX parity (mark/space) with Python-Serial on Linux.

2011-11-21 Thread David Riley

On Nov 21, 2011, at 12:25 PM, gene heskett wrote:

> And that is 9600 baud 8n1 on both ends.  Ascii is normally 7 bit and will 
> have a low 8th bit if fed normal ascii data, so how is the 8th bit getting 
> set other than purposely setting 7M1 on the other end of the cable?

That's what I thought the OP was doing; it sounds like he's trying to receive 
7M1 in Minicom using 8N1 on the terminal and getting garbled data because the 
high bit is set (because the other end is sending 7M1).  I never meant to imply 
that 8N1 would give garbled data if both ends were set to it; indeed, that's 
pretty much standard communications settings for short cables in low to 
moderate noise environments.  If anyone else read it that way, that's not what 
I meant. :-)

- Dave

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


Re: Non-POSIX parity (mark/space) with Python-Serial on Linux.

2011-11-21 Thread gene heskett
On Monday, November 21, 2011 11:58:53 AM David Riley did opine:

> On Nov 21, 2011, at 11:28 AM, Matthew Lenz wrote:
> > Using 8N1 under minicom with this device resulted in garbled text when
> > once connected.  Connection using 7M1 resulted in the correct text. 
> > So there must be something else that needs to be done in my python
> > program correct?
> 
> Under minicom in 8N1, it's going to look garbled because the high bit
> will always be set. Minicom will try to spit out those characters
> anyway, which will print out whatever extended ASCII garbage your
> terminal supports in the 0x80-0xFF range. Programmatically, though, you
> can strip off the high bit when you're receiving it in Python.

I have been using 8n1 in minicom for years, never ever had such a problem. 
In fact, I don't even know if I can set the path to mark parity as it is so 
rarely used.  E or O as error detectors are much more commonly used.

Example copy/paste from minicom, talking to a trs-80 Color Computer 3 
running a shell under nitros9, which is a bit like unix.  I am asking it 
for the settings of its own output path, .1=stdout:

{t2|07}/DD/NITROS9/dw3install/6309L2/SCRIPTS:tmode .1
/t2
 upc=00 bso=01 dlo=00 eko=01 alf=01 nul=00 pau=01 pag=18
 bsp=08 del=18 eor=0D eof=1B rpr=09 dup=01 psc=17 int=03
 qut=05 bse=08 ovf=07 par=01 bau=06 xon=00 xof=00
{t2|07}/DD/NITROS9/dw3install/6309L2/SCRIPTS:

And that is 9600 baud 8n1 on both ends.  Ascii is normally 7 bit and will 
have a low 8th bit if fed normal ascii data, so how is the 8th bit getting 
set other than purposely setting 7M1 on the other end of the cable?

> "Space" parity, on the other hand, should look normal under Minicom
> because the high bit will always be low, giving you standard 7-bit
> ASCII.
> 
Yes.

> - Dave


Cheers, Gene
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
My web page: 
Everything is controlled by a small evil group to which, unfortunately,
no one we know belongs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Non-POSIX parity (mark/space) with Python-Serial on Linux.

2011-11-21 Thread David Riley
On Nov 21, 2011, at 11:52 AM, Matthew Lenz wrote:

> Ahh. Ok.  So how would I go about doing that with python?  I think in perl 
> (sorry for the naughty word) I could use the tr// (translate) but is there a 
> quick way to do so with python?  Is it going to be necessary to convert 
> commands I SEND to the device or only convert what I receive?

The high-level overview is that you'll want to OR in 0x80 on transmit, and AND 
0x7F on receive (thus inserting the high bit when you send it out and removing 
it when you receive).  If you wanted to be extra-sure you're receiving things 
correctly, you should also check to see if your value ANDed with 0x80 is not 
zero.

In Python 2.x, as mentioned, when you iterate over a string, you get a bunch of 
tiny one-character strings, which you then need to convert into numbers with 
ord() and back into strings with chr() when you re-concatenate it.  ord() and 
chr() may be familiar to you from Perl.  For example, you could do this on 
reception:



# However you get your data out of serial
received_str = receive_my_string()

ord_str = [ord(x) for x in received_str]

# An exception may be extreme in this case, but hey.  Note that
# the filter() function actually returns a list of all the
# characters that don't have the high bit set, so you could
# actually use that if you wanted to.
if filter((lambda x: x < 0x80), ord_str):
   raise IOError("Received character without mark parity")

return "".join([chr(x & 0x7F) for x in received_str])



In Python 3.x, iterating over a bytes array (which is, hopefully, what your 
serial interface returns) will give you a bunch of ints, so you shouldn't need 
to do the conversions:




# However you get your data out of serial
received_bytes = receive_my_string()

# In Python 3.x, filter() returns an iterator, which is generally a
# better thing to return, but doesn't test as nicely for a bool.
for b in received_bytes:
   if b < 0x80:
   raise IOError("Received character without mark parity")

# None of this "".join() nonsense with byte arrays!
return bytes([(x & 0x7F) for x in received_bytes])





There are surely more efficient ways to do what I've typed up there, but those 
should work pretty well for whatever you're looking to do.  For sending, you 
pretty much want to swap (x & 0x7F) with (x | 0x80) to insert that high bit.


- Dave


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


Re: decorators and closures

2011-11-21 Thread Andrea Crotti

On 11/21/2011 05:11 PM, Dave Angel wrote:


You didn't mention what version of Python you're running.  With Python 
2, I got very different results.  So I switched to Python 3.2, and I 
still don't get exactly what you have.


A closure is needed if there's some non-global data outside the 
function definition (code object) that's needed by the function 
object.  As you supply the code I don't need a closure.  But if I add 
a local variable in test_decorate(), and refer to it in dec(), then I 
get one.  Not the same as yours.


You left out the import and the definition line for test_decorate.  
Did you leave anything else?  And what version of Python are you 
using?  Are you perhaps running in a shell, as opposed to running code 
directly from a source file?


I use python 2.7, and actually the whole source is this (test_decorate.py):

def dec(fn):
  def _dec():
  fn()

  return _dec

@dec
def fun():
  print("here")

fun()


Using ipython:
import test_decorate
dis.dis(test_decorate)
--
http://mail.python.org/mailman/listinfo/python-list


Re: What I do and do not know about installing Python on Win 7 with regard to IDLE.

2011-11-21 Thread Andrea Crotti

On 11/21/2011 04:39 PM, W. eWatson wrote:

...
I'm using Win 7 Premium.

So unless some brilliant idea appears, that leaves me with the choice 
of not using Python or this suggestion... (Let's not get off into 
other variations of other "Pythons" like Active..."):


Someone suggested using the mail list at 
. What's 
different about that list than this NG? Does the "org" suggest that 
the inhabitants of that list are more likely associated with the 
people who are responsible for constructing Python?


Comments?


I only see windows and users-related problems, not much having to do 
with Python actually.
Moreover, nothing forces you to use it, and with this attitude is not 
bad that you stay way

from it, no offense of course.
--
http://mail.python.org/mailman/listinfo/python-list


Re: decorators and closures

2011-11-21 Thread Dave Angel

On 11/21/2011 10:35 AM, Andrea Crotti wrote:

On 11/21/2011 03:06 PM, Dave Angel wrote:

Your function 'nested' isn't nested, 'fun' is. What you discovered is
that a decorator is always executed, every time a nested decorated
function is defined.

You've also ust proved that it would be an incompatible change.
Doesn't that answer the question? An optimizer that changes the
behavior isn't usually desirable.


Yes sure I think it makes perfectly sense, because you actually redefine
a local variable every time..

Another thing (which was also the reason of the subject), I tried to
disassemble the following:
def dec(fn):
def _dec():
fn()

return _dec

@dec
def fun():
print("here")

fun()

And I get this:
In [29]: dis.dis(test_decorate)
Disassembly of dec:
2 0 LOAD_CLOSURE 0 (fn)
3 BUILD_TUPLE 1
6 LOAD_CONST 1 ()
9 MAKE_CLOSURE 0
12 STORE_FAST 1 (_dec)

5 15 LOAD_FAST 1 (_dec)
18 RETURN_VALUE

Disassembly of fun:
3 0 LOAD_DEREF 0 (fn)
3 CALL_FUNCTION 0
6 POP_TOP
7 LOAD_CONST 0 (None)
10 RETURN_VALUE


Looking up the definition of the single calls didn't help much, so why
do we need
for example MAKE_CLOSURE?
Is MAKE_CLOSURE just more generic maybe?



You didn't mention what version of Python you're running.  With Python 
2, I got very different results.  So I switched to Python 3.2, and I 
still don't get exactly what you have.


A closure is needed if there's some non-global data outside the function 
definition (code object) that's needed by the function object.  As you 
supply the code I don't need a closure.  But if I add a local variable 
in test_decorate(), and refer to it in dec(), then I get one.  Not the 
same as yours.


You left out the import and the definition line for test_decorate.  Did 
you leave anything else?  And what version of Python are you using?  Are 
you perhaps running in a shell, as opposed to running code directly from 
a source file?




--

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


Re: sqlalchemy beginner

2011-11-21 Thread John Gordon
In  Jabba Laci 
 writes:

> SAWarning: Unicode column received non-unicode default value.
>   Column('display_name', Unicode(255), default=''),

Perhaps it would help to supply the default value as a Unicode string
instead of a plain string?

  Column('display_name', Unicode(255), default=u''),

-- 
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: Non-POSIX parity (mark/space) with Python-Serial on Linux.

2011-11-21 Thread Matthew Lenz
Ahh. Ok.  So how would I go about doing that with python?  I think in perl 
(sorry for the naughty word) I could use the tr// (translate) but is there a 
quick way to do so with python?  Is it going to be necessary to convert 
commands I SEND to the device or only convert what I receive?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Non-POSIX parity (mark/space) with Python-Serial on Linux.

2011-11-21 Thread David Riley
On Nov 21, 2011, at 11:28 AM, Matthew Lenz wrote:

> Using 8N1 under minicom with this device resulted in garbled text when once 
> connected.  Connection using 7M1 resulted in the correct text.  So there must 
> be something else that needs to be done in my python program correct?

Under minicom in 8N1, it's going to look garbled because the high bit will 
always be set. Minicom will try to spit out those characters anyway, which will 
print out whatever extended ASCII garbage your terminal supports in the 
0x80-0xFF range. Programmatically, though, you can strip off the high bit when 
you're receiving it in Python.

"Space" parity, on the other hand, should look normal under Minicom because the 
high bit will always be low, giving you standard 7-bit ASCII.

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


What I do and do not know about installing Python on Win 7 with regard to IDLE.

2011-11-21 Thread W. eWatson


My criterion for success is that it puts IDLE as a choice for editor on 
the menu produced with a right-click on a py file. So far no response on 
this has solved the problem.


I know it sets up that way on a 2.5 and 2.4 on other PCs I have.

I know at one time it worked on my 64-bit Win 7 PC,  which likely had a 
32-bit version installed on it.  After something like six months of 
modest use it stopped working as above. No IDLE choice.


I know by installing a 64-bit version, 3.2.2 failed the IDLE criterions 
as described. No IDLE.


I do know that IDLE appears on the Win 7 Start menu, but, when used, 
nothing happens.  Well, OK, for about 3 seconds the Win 7 "working" icon 
spins around then zip, nothing.  Further, right-clicking on Properties 
of IDLE (GUI) produces a tabbed dialog.  It shows Start in: 
c:\Python32\, and None for shortcut.  There is a compatibility tab, 
which I've set to Win7.  I think there's a troubleshooter there too, but 
I haven't used it. Under the Details tab, it shows Name: IDLE(Python 
Gui).lnk. Folder Path as: c:\ProgramData\Microsoft\Windows\Start... 
Nothing after the "...".  Attributes: A


Going directly to ...\Lib\idlelib\idle.pyw produces the spinning icon. 
At least, that's what happens in 3.2.2, but in the 32-bit versions I 
tried, I would get "invalid Win 32 app".


When I rebooted my system a few hours after installing 3.2.2, because 
the PC was running really slowly--not because of Python, I was greeted 
by a couple of interesting messages as the desktop was populated.


I can execute Python from the command line.

1. Specified module could not be found: Load Lib, python.dll.

2. \ProgramFiles(x86)\uniblueDrivers\Scanner (x86) Python26.dll. I'm 
sure this is related to Winamp, which I had installed a month ago.  It 
had some "crazy" choice to scan for new drivers.   Of course, if it 
found one-connected with Python, and if you wanted it, $$$.  I think 
this message is a red herring. I may re-install Winamp to get rid of 
that uniblue tool that seems like nothing more than an ad.


Some have suggested a registry problem, but I don't have a clue how to 
play with that, or somehow clean it up, if there is a problem.  My PC 
behaves normally


I'm using Win 7 Premium.

So unless some brilliant idea appears, that leaves me with the choice of 
not using Python or this suggestion... (Let's not get off into other 
variations of other "Pythons" like Active..."):


Someone suggested using the mail list at 
. What's different 
about that list than this NG? Does the "org" suggest that the 
inhabitants of that list are more likely associated with the people who 
are responsible for constructing Python?


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


Re: Non-POSIX parity (mark/space) with Python-Serial on Linux.

2011-11-21 Thread Chris Angelico
On Tue, Nov 22, 2011 at 3:28 AM, Matthew Lenz  wrote:
> Using 8N1 under minicom with this device resulted in garbled text when once 
> connected.  Connection using 7M1 resulted in the correct text.  So there must 
> be something else that needs to be done in my python program correct?

Using 8N1 when it's really 7M1 means you have the high bit set on
every byte. I don't know if there's an easy way to do this fast in
Python, but what you need to do is mask them all off... I'm not sure
if there's a better way, but this ought to work:

string = "".join(chr(ord(x)&0x7f) for x in string)

In Python 3, iterating over a 'bytes' string produces integers, so
omit the ord() call. Other than that, code is not tested.

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


Re: How to Get Data from DictReader for CSV Files

2011-11-21 Thread GZ
Hi,

On Nov 21, 7:42 am, ray  wrote:
> I don't see how to get my data from the output.  I can see the data in
> the rows but it is mixed in with the field names.  That is, the data I
> get comes out as:
> fieldname1 : data1 , fieldname2 : data2 , etc.
>
> import csv
> linelist=open( "C:/Users/me/line_list_r0.csv", "rb" )
> csvReader= csv.DictReader( linelist, dialect='excel' )
> for data in csvReader:
>         print data
> linelist.close()
>
> I want to pass this data as arrays or lists to another module such as:
> myfunction(data1, data2, data3)
>
> How do I get the data I want out of the pair fieldname1 : data1?
>
> Thanks,
> ray
>
>

It returns a dict(). You can reference the fields with
data['fieldname1'], etc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Non-POSIX parity (mark/space) with Python-Serial on Linux.

2011-11-21 Thread Matthew Lenz
Using 8N1 under minicom with this device resulted in garbled text when once 
connected.  Connection using 7M1 resulted in the correct text.  So there must 
be something else that needs to be done in my python program correct?

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


sqlalchemy beginner

2011-11-21 Thread Jabba Laci
Hi,

I'm reading the Essential SQLAlchemy book from O'Reilly. It explains
SqlAlch 0.4 but my current version is 0.7 and there are some
differences.

Here is an example from the book:

user_table = Table('tf_user', metadata,
Column('id', Integer, primary_key=True),
Column('user_name', Unicode(16), unique=True, nullable=False),
Column('password', Unicode(40), nullable=False),
Column('display_name', Unicode(255), default=''),
Column('created', DateTime, default=datetime.now)
)

Here I get the following warning:

SAWarning: Unicode column received non-unicode default value.
  Column('display_name', Unicode(255), default=''),

Changing Unicode(255) to String(255) makes the warning disappear but
I'm not sure if it's the correct solution.

For table names, the book uses the prefix convention 'tf_' but what
does it mean? 't' is table, but what is 'f'?

Thanks,

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


Re: How to: Coordinate DictReader and Reader for CSV

2011-11-21 Thread Neil Cerutti
On 2011-11-21, Neil Cerutti  wrote:
> On 2011-11-21, ray  wrote:
>> Is there a way to capture the keys outside of the for loop so
>> when the for loop is entered, only data is extracted?
>
> I have sometimes done the following type of thing, since
> DictReader doesn't offer an attribute providing the field names.
> This is Python 3.3.2 code, so revise boilerplate if necessary.
>
> # Open once as a csv.reader instance to get the field names, in
> # order.
> with open(in_file_name, newline='') as in_file:
> reader = csv.reader(in_file)
> fields = next(reader)

Equal to reader.next() in 2.x Python, I believe.

> # Open it again as a csv.DictReader instance to do actual work,
> # writing revised lines to the output file as I go.
> with open(in_file_name, newline=') as in_file:
>   with open(out_file_name, "w", newline='') as out_file:
> reader = csv.DictReader(in_file)
> writer = csv.DictWriter(out_file, fieldnames=fields)
> # Write header line
> writer.writerow({f: f for n in fields})

Oops! {f: f for f in fields}. Sorry about that.

> for record in reader:
> # Change a few fields
>   # [...]
>   writer.writerow(record)


-- 
Neil Cerutti
  "This room is an illusion and is a trap devisut by Satan.  Go
ahead and dauntlessly!  Make rapid progres!"
  --Ghosts 'n Goblins
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to: Coordinate DictReader and Reader for CSV

2011-11-21 Thread Neil Cerutti
On 2011-11-21, ray  wrote:
> Is there a way to capture the keys outside of the for loop so
> when the for loop is entered, only data is extracted?

I have sometimes done the following type of thing, since
DictReader doesn't offer an attribute providing the field names.
This is Python 3.3.2 code, so revise boilerplate if necessary.

# Open once as a csv.reader instance to get the field names, in
# order.
with open(in_file_name, newline='') as in_file:
reader = csv.reader(in_file)
fields = next(reader)

# Open it again as a csv.DictReader instance to do actual work,
# writing revised lines to the output file as I go.
with open(in_file_name, newline=') as in_file:
  with open(out_file_name, "w", newline='') as out_file:
reader = csv.DictReader(in_file)
writer = csv.DictWriter(out_file, fieldnames=fields)
# Write header line
writer.writerow({f: f for n in fields})
for record in reader:
# Change a few fields
# [...]
writer.writerow(record)

-- 
Neil Cerutti
  "This room is an illusion and is a trap devisut by Satan.  Go
ahead and dauntlessly!  Make rapid progres!"
  --Ghosts 'n Goblins
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: decorators and closures

2011-11-21 Thread Andrea Crotti

On 11/21/2011 03:06 PM, Dave Angel wrote:
Your function 'nested' isn't nested, 'fun' is.  What you discovered is 
that a decorator is always executed, every time a nested decorated 
function is defined.


You've also ust proved that it would be an incompatible change.  
Doesn't that answer the question?  An optimizer that changes the 
behavior isn't usually desirable.


Yes sure I think it makes perfectly sense, because you actually redefine 
a local variable every time..


Another thing (which was also the reason of the subject), I tried to 
disassemble the following:

  def dec(fn):
  def _dec():
  fn()

  return _dec

  @dec
  def fun():
  print("here")

  fun()

And I get this:
  In [29]: dis.dis(test_decorate)
  Disassembly of dec:
2   0 LOAD_CLOSURE 0 (fn)
3 BUILD_TUPLE  1
6 LOAD_CONST   1 (0x1c4b930, file "test_decorate.py", line 2>)

9 MAKE_CLOSURE 0
   12 STORE_FAST   1 (_dec)

5  15 LOAD_FAST1 (_dec)
   18 RETURN_VALUE

  Disassembly of fun:
3   0 LOAD_DEREF   0 (fn)
3 CALL_FUNCTION0
6 POP_TOP
7 LOAD_CONST   0 (None)
   10 RETURN_VALUE


Looking up the definition of the single calls didn't help much, so why 
do we need

for example MAKE_CLOSURE?
Is MAKE_CLOSURE just more generic maybe?
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to: Coordinate DictReader and Reader for CSV

2011-11-21 Thread ray
On Nov 21, 7:59 am, Neil Cerutti  wrote:
> On 2011-11-21, ray  wrote:
>
> > I am trying to get the data from a CSV file into variables.  I have
> > used DictReader to get the field names and I can report them.  When I
> > attempt to look at the data, every row shows the combination of
> > fieldname:data.  How do I get the data out?

> > linelist=open( "C:/Users/thisuser/Documents/Projects/Bootstrap Plan
> > Design Tool/Sandbox/line_list_r0a.csv", "rb" )
> > csvDictReader=csv.DictReader( linelist, dialect='excel' )
> > for data in csvReader:
> >         print data[0]
> >         print data[1]
> >         print data[2]
> >         print data[3]
> > linelist.close()
>
> The elements yielded by a DictReader iterator are dictionaries,
> and the keys are the headings of the csv file. So replace those
> integers with strings representing the headings of your file.
>
> If the headings are actually those numbers, you want:
>
> [...]
>     print data['0']
>     print data['1']
>     print data['2']
>     print data['3']
>     print data['4']
> [...]
>
> --
> Neil Cerutti
>   "This room is an illusion and is a trap devisut by Satan.  Go
> ahead and dauntlessly!  Make rapid progres!"
>   --Ghosts 'n Goblins

Neil,

Thank you for your efforts.

When I use the 0, 1, etc. in the data[x] slot, I get some data.  When
I put a string in, I get an error stating:
TypeError: list indices must be integers, not str

But your suggestion has helped my better understand my problem. The
output is first a list of the keys and then the associated data.  The
difficulty is that I want to pass the data to another function will I
am in the 'for' loop.  But the first data out is keys and that is not
the data I want to send to the other function.  Is there a way to
capture the keys outside of the for loop so when the for loop is
entered, only data is extracted?

Thanks,
ray

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


Re: decorators and closures

2011-11-21 Thread Dave Angel

On 11/21/2011 09:44 AM, Andrea Crotti wrote:
With one colleague I discovered that the decorator code is always 
executed, every time I call

a nested function:

def dec(fn):
print("In decorator")
def _dec():
fn()

return _dec

def nested():
@dec
def fun():
print("here")

nested()
nested()

Will give:
In decorator
In decorator

So we were wondering, would the interpreter be able to optimize this 
somehow?

I was betting it's not possible, but I'm I would like to be wrong :)
Your function 'nested' isn't nested, 'fun' is.  What you discovered is 
that a decorator is always executed, every time a nested decorated 
function is defined.


You've also ust proved that it would be an incompatible change.  Doesn't 
that answer the question?  An optimizer that changes the behavior isn't 
usually desirable.



--

DaveA

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


decorators and closures

2011-11-21 Thread Andrea Crotti
With one colleague I discovered that the decorator code is always 
executed, every time I call

a nested function:

def dec(fn):
print("In decorator")
def _dec():
fn()

return _dec

def nested():
@dec
def fun():
print("here")

nested()
nested()

Will give:
In decorator
In decorator

So we were wondering, would the interpreter be able to optimize this 
somehow?

I was betting it's not possible, but I'm I would like to be wrong :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Format the ouput in my python code

2011-11-21 Thread Dave Angel

On 11/21/2011 09:27 AM, Dave Angel wrote:

On 11/21/2011 07:13 AM, sl33k wrote:

I am printing the numbers from 1 to 100. In that, I want to display
multiples of 3,5 and of both as mulof3, mul0f5 and mulof3and5
respectively.

  I am getting the output I want but I would like to format the output
to print only 10 number per line. How do I go about doing this?

for i in range(1, 101):
 if i % 3 == 0:
 if i % 5 == 0:
 print 'mulof3and5',
 else:
 print 'mulof3',
 elif i % 5 == 0:
 print 'mulof5',
 else:
 print i

Change that loop into a generator, having it return values rather than 
printing them.  Then call that generator in a for-loop, something like:


for index, val in enumerate(mygen):
print val,
if not index%10: print


Oops.  That was untested, and it probably wasn't quite what you wanted.  
More likely something like (untested):


for index, val in enumerate(mygen):
 print val,
 if not ((index+1)%10): print




--

DaveA

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


Re: Format the ouput in my python code

2011-11-21 Thread Dave Angel

On 11/21/2011 07:13 AM, sl33k wrote:

I am printing the numbers from 1 to 100. In that, I want to display
multiples of 3,5 and of both as mulof3, mul0f5 and mulof3and5
respectively.

  I am getting the output I want but I would like to format the output
to print only 10 number per line. How do I go about doing this?

for i in range(1, 101):
 if i % 3 == 0:
 if i % 5 == 0:
 print 'mulof3and5',
 else:
 print 'mulof3',
 elif i % 5 == 0:
 print 'mulof5',
 else:
 print i

Change that loop into a generator, having it return values rather than 
printing them.  Then call that generator in a for-loop, something like:


for index, val in enumerate(mygen):
print val,
if not index%10: print



--

DaveA

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


Re: Non-POSIX parity (mark/space) with Python-Serial on Linux.

2011-11-21 Thread Nizamov Shawkat
2011/11/21  :
> I'm working on a project where I need to communicate with some devices via 
> modem which have the possibility of using MARK and SPACE parity.  These are 
> not defined by POSIX and therefore are not directly supported under Linux.
>
> I've found the following discussion on the topic:
>
> http://www.lothosoft.ch/thomas/libmip/markspaceparity.php
>
> and I have been trying to use this information (since the TERMIOS module is 
> available) to proceed with the communication.
>
> I was able to use minicom to determine that the first device I started 
> testing with uses 7M1 but cannot figure out how to implement the solution 
> described by the author above.
>


"The modes 7M1 (7 data bits, MARK parity, 1 stop bit) and 7S1 (7 data
bits, SPACE parity, 1 stop bit) can easily be emulated using 8N1 (0
data bits, NO parity, 1 stop bit) and setting the 8th data bit to 1
resp. 0. This is relatively simple to implement and cannot be
distinguished by the receiver."

It means that 7M1 === 8N1. Set 8N1 mode on your side and 7M1 on the
other side. I really do not understand what is the reason to have
dedicated 7M1 or 7S1 mode - it is no different from regular 8 bit mode
from the hardware point of view. From the software point of view it is
just the matter of the definition of the highest bit. In other words,
7M1/7S1 are two complementary subsets of a single 8N1 set.

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


Re: Non-POSIX parity (mark/space) with Python-Serial on Linux.

2011-11-21 Thread Matthew Lenz
I should also note that I am aware of the following discussion on the newsgroup:

https://groups.google.com/d/msg/comp.lang.python/1HyCqPSOf50/eQINFrrFKwoJ

However, I believe this refers to implementing the solution for 8M1 and 8S1.
-- 
http://mail.python.org/mailman/listinfo/python-list


Non-POSIX parity (mark/space) with Python-Serial on Linux.

2011-11-21 Thread mlenz
I'm working on a project where I need to communicate with some devices via 
modem which have the possibility of using MARK and SPACE parity.  These are not 
defined by POSIX and therefore are not directly supported under Linux.

I've found the following discussion on the topic:

http://www.lothosoft.ch/thomas/libmip/markspaceparity.php

and I have been trying to use this information (since the TERMIOS module is 
available) to proceed with the communication.

I was able to use minicom to determine that the first device I started testing 
with uses 7M1 but cannot figure out how to implement the solution described by 
the author above.

Any pointers would be greatly appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to: Coordinate DictReader and Reader for CSV

2011-11-21 Thread Neil Cerutti
On 2011-11-21, ray  wrote:
> I am trying to get the data from a CSV file into variables.  I have
> used DictReader to get the field names and I can report them.  When I
> attempt to look at the data, every row shows the combination of
> fieldname:data.  How do I get the data out?
> linelist=open( "C:/Users/rjoseph/Documents/Projects/Bootstrap Plan
> Design Tool/Sandbox/line_list_r0a.csv", "rb" )
> csvDictReader=csv.DictReader( linelist, dialect='excel' )
> for data in csvReader:
> print data[0]
> print data[1]
> print data[2]
> print data[3]
> linelist.close()

The elements yielded by a DictReader iterator are dictionaries,
and the keys are the headings of the csv file. So replace those
integers with strings representing the headings of your file.

If the headings are actually those numbers, you want:

[...]
print data['0']
print data['1']
print data['2']
print data['3']
print data['4']
[...]

-- 
Neil Cerutti
  "This room is an illusion and is a trap devisut by Satan.  Go
ahead and dauntlessly!  Make rapid progres!"
  --Ghosts 'n Goblins
-- 
http://mail.python.org/mailman/listinfo/python-list


How to Get Data from DictReader for CSV Files

2011-11-21 Thread ray
I don't see how to get my data from the output.  I can see the data in
the rows but it is mixed in with the field names.  That is, the data I
get comes out as:
fieldname1 : data1 , fieldname2 : data2 , etc.

import csv
linelist=open( "C:/Users/me/line_list_r0.csv", "rb" )
csvReader= csv.DictReader( linelist, dialect='excel' )
for data in csvReader:
print data
linelist.close()

I want to pass this data as arrays or lists to another module such as:
myfunction(data1, data2, data3)

How do I get the data I want out of the pair fieldname1 : data1?

Thanks,
ray
-- 
http://mail.python.org/mailman/listinfo/python-list


How to: Coordinate DictReader and Reader for CSV

2011-11-21 Thread ray
I am trying to get the data from a CSV file into variables.  I have
used DictReader to get the field names and I can report them.  When I
attempt to look at the data, every row shows the combination of
fieldname:data.  How do I get the data out?
linelist=open( "C:/Users/rjoseph/Documents/Projects/Bootstrap Plan
Design Tool/Sandbox/line_list_r0a.csv", "rb" )
csvDictReader=csv.DictReader( linelist, dialect='excel' )
for data in csvReader:
print data[0]
print data[1]
print data[2]
print data[3]
linelist.close()

Thanks,
ray
-- 
http://mail.python.org/mailman/listinfo/python-list


JSON passing protocol

2011-11-21 Thread Alec Taylor
Good morning,

I'm planning on assembling my django templates onto mobile apps using
a JSON passing protocol, probably tunnels through HTTP.

What's available?

Thanks for all information,

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


New memcached module

2011-11-21 Thread Jayson Santos
Hi guys, I have created a pure python module [1] to work with
memcached in binary protocol with SASL authentication.
I need some contributors or people to discuss some idead about it,
anyone is free to contact me, any help will be appreciated.
Thank You
Jayson Reis

[1] https://github.com/jaysonsantos/python-binary-memcached
-- 
http://mail.python.org/mailman/listinfo/python-list


Multiple Threads - I/O in Same File

2011-11-21 Thread Nikunj.Badjatya
Hi All,


Just a question in general.  Is it possible that we have opened one file in r+ 
mode ( file1.txt ).

We have 2 threads,

* Thread1 will continuously 'only read' the file in a loop.

* Thread2 will only update the data in the file ( say a number < 100 ).

Now thread2 has called other script ( written in say Perl/Powershell using 
subprocess.call() ) and those scripts are inturn updating ( only writing ) into 
that file by their own file i/o mechanism.



Is it possible by any chance? One file being shared between different processes 
one is only updating and other is only reading ..? Will this work in practical 
and what can be the complications ?


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


Re: Is there any way to unimport a library

2011-11-21 Thread Jean-Michel Pichavant

Jean-Michel Pichavant wrote:

Gelonida N wrote:

I wondered whether there is any way to un-import a library, such, that
it's occupied  memory and the related shared libraries are released.


My usecase is following:


success = False
try:
import lib1_version1 as lib1
import lib2_version1 as lib2
success = True
except ImportError:
pass
if not success:
try:
import lib1_version2 as lib1
import lib2_version2 as lib2
success = True
except importError:
pass
if not success:
. . .



Basically if I am not amble to import lib1_version1 AND lib2_version1,
then I wanted to make sure, that lib1_version1 does not waste any memory


At this moment this is more a thought excercise than a real issue, but I
thought that perhaps somebody encountered this kind of issue and had an
idea how to deal with such situations.

One solution, that I could imagine is running the program a first time,
detect all existing libraries and write out a config file being use
the next time it is run, such, that immediately the right libs are 
imported.


  
Short answer for unimporting modules : Not possible (yes there is a 
long one :o) ).


One approach to your problem is to test for module existence before 
importing any module.


import imp

def impVersion(version)
   try:
   imp.find_module('lib1_version%s' % version)
   imp.find_module('lib2_version%s' % version)
   except ImportError:
   raise
   else:
   lib1 = __import__('lib1_version%s' % version)
   lib2 = __import__('lib2_version%s' % version)

# using a for loop to avoid to many nested try statement
for version in [1,2,3,4]:
   try:
   impVersion(version)
   except ImportError:
   continue
   break

if not lib1 or not lib2:
   # no lib imported
   pass

Using this code allows you to import your library only if all 
conditions are met, preventing you from rolling back in case of error.


Jean-Michel


there are missing
global lib1
global lib2
statements right before assigning lib1 and lib2.

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


Re: ProgressBar - Python and Powershell

2011-11-21 Thread Alec Taylor
New thread!

On Mon, Nov 21, 2011 at 11:27 PM,   wrote:
> Hey Thanks. Will do that.
>
> Just a question in general.  Is it possible that we have opened one file in 
> r+ mode ( file1.txt ). We have 2 threads, thread1 will continuously only read 
> the file in a loop. Thread2 will only update the data in the file. Now 
> thread2 has called other script ( written in say Perl/Powershell ) and those 
> scripts are inturn updating ( only writing ) into that file by their own file 
> i/o mechanism.
> Is it possible by any chance? One file being shared between different 
> processes one is updating and other is reading ..? Will this work in 
> practical and what can be the complications ?
>
>
>
> -Original Message-
> From: Alec Taylor [mailto:alec.tayl...@gmail.com]
> Sent: Monday, November 21, 2011 5:23 PM
> To: Badjatya, Nikunj
> Subject: Re: ProgressBar - Python and Powershell
>
> WiX will manage all the progress bar stuff for you.
>
> Just wrap it all in
>
> On Mon, Nov 21, 2011 at 9:44 PM,   wrote:
>> Yes I am executing powershell commands into virtual machines.
>>
>> Will have a look at WiX.
>>
>> But please, Answer my questions:
>>
 My questions are:

 1.       Can I have a better shared mechanism between python and
 powershell.?  As I am using a file here. Reading + writing in python and
 writing only in powershell.  !

 2.       Does this thread mechanism work.? I am yet to implement and test
 it.! :P What can be the possible shortfalls.?
>>
>> Thanks
>> Nikunj
>>
>> -Original Message-
>> From: Alec Taylor [mailto:alec.tayl...@gmail.com]
>> Sent: Monday, November 21, 2011 11:59 AM
>> To: Badjatya, Nikunj
>> Cc: python-list@python.org
>> Subject: Re: ProgressBar - Python and Powershell
>>
>> So you're executing Powershell commands into Virtual Machines?
>>
>> Add this into the installer (probably WiX is your best bet)
>>
>> On Mon, Nov 21, 2011 at 3:40 AM,   wrote:
>>> Thanks for reply.
>>> Python and Powershell are required because the installer would deal in 
>>> virtual machines ( VMware environment ).
>>> Some prechecks and postconfig are required in both VMware and Windows 
>>> environment. For dealing with VMware environment powershell has the best 
>>> bonding. For windows I am  using Python.
>>>
>>> I am new to this field and do not know if there is an alternative 
>>> available.! Can you please suggest an alternative to Powershell in VM 
>>> environment. ?
>>>
>>> The current look of the installer is completely command line based.
>>>
>>>
>>> -Original Message-
>>> From: Alec Taylor [mailto:alec.tayl...@gmail.com]
>>> Sent: Sunday, November 20, 2011 7:22 PM
>>> To: Badjatya, Nikunj
>>> Cc: python-list@python.org
>>> Subject: Re: ProgressBar - Python and Powershell
>>>
>>> Why are you writing an installer in Python and Powershell?
>>>
>>> Just write an installer in WiX, NSIS or Inno like the rest of the sane 
>>> world.
>>>
>>> Alternatively take a look at MakeMSI or the script python uses to
>>> generate there .MSI.
>>>
>>> Anything else is WAY too non-standard to consider.
>>>
>>> On Mon, Nov 21, 2011 at 12:01 AM,   wrote:
 Can anyone throw some light on this please ! ?





 From: python-list-bounces+nikunj.badjatya=emc@python.org
 [mailto:python-list-bounces+nikunj.badjatya=emc@python.org] On Behalf 
 Of
 nikunj.badja...@emc.com
 Sent: Thursday, November 17, 2011 4:10 PM
 To: python-list@python.org
 Subject: ProgressBar - Python and Powershell



 Hi All,



 I am using Python 2.7, windows Env.

 I have an Installer written in Python(45%) and Powershell(55%) which is 
 used
 to install Virtual Machines at specific locations. It is single threaded.

 I am trying to implement a ProgressBar  for this installer. So that the 
 user
 will come to know the progress of the installation.

 I am using pypi progressbar module.

 The top script is in python which inturns calls powershell scripts using
 subprocess.call() and proceeds with the installation.



 I am taking a shared file between python and powershell, so that diff
 functions can update their %age completion level in to the file. Ex. 
 Func1()
 updates it to 5%,  func2() will add its own 5% to it.. and so on.

 At the start of the (main.py) script I am creating a thread whose sole
 purpose would be to keep "READ" a temp file for a new entry in it.

 Based on this entry I can have my thread update the progressbar on the
 console.



 My questions are:

 1.   Can I have a better shared mechanism between python and
 powershell.?  As I am using a file here. Reading + writing in python and
 writing only in powershell.  !

 2.   Does this thread mechanism work.? I am yet to implement and test
 it.! :P What can be the possible shortfalls.?


>

Re: Is there any way to unimport a library

2011-11-21 Thread Jean-Michel Pichavant

Gelonida N wrote:

I wondered whether there is any way to un-import a library, such, that
it's occupied  memory and the related shared libraries are released.


My usecase is following:


success = False
try:
import lib1_version1 as lib1
import lib2_version1 as lib2
success = True
except ImportError:
pass
if not success:
try:
import lib1_version2 as lib1
import lib2_version2 as lib2
success = True
except importError:
pass
if not success:
. . .



Basically if I am not amble to import lib1_version1 AND lib2_version1,
then I wanted to make sure, that lib1_version1 does not waste any memory


At this moment this is more a thought excercise than a real issue, but I
thought that perhaps somebody encountered this kind of issue and had an
idea how to deal with such situations.

One solution, that I could imagine is running the program a first time,
detect all existing libraries and write out a config file being use
the next time it is run, such, that immediately the right libs are imported.

  
Short answer for unimporting modules : Not possible (yes there is a long 
one :o) ).


One approach to your problem is to test for module existence before 
importing any module.


import imp

def impVersion(version)
   try:
   imp.find_module('lib1_version%s' % version)
   imp.find_module('lib2_version%s' % version)
   except ImportError:
   raise
   else:
   lib1 = __import__('lib1_version%s' % version)
   lib2 = __import__('lib2_version%s' % version)

# using a for loop to avoid to many nested try statement
for version in [1,2,3,4]:
   try:
   impVersion(version)
   except ImportError:
   continue
   break

if not lib1 or not lib2:
   # no lib imported
   pass

Using this code allows you to import your library only if all conditions 
are met, preventing you from rolling back in case of error.


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


RE: ProgressBar - Python and Powershell

2011-11-21 Thread Nikunj.Badjatya
Hey Thanks. Will do that.

Just a question in general.  Is it possible that we have opened one file in r+ 
mode ( file1.txt ). We have 2 threads, thread1 will continuously only read the 
file in a loop. Thread2 will only update the data in the file. Now thread2 has 
called other script ( written in say Perl/Powershell ) and those scripts are 
inturn updating ( only writing ) into that file by their own file i/o 
mechanism. 
Is it possible by any chance? One file being shared between different processes 
one is updating and other is reading ..? Will this work in practical and what 
can be the complications ?  



-Original Message-
From: Alec Taylor [mailto:alec.tayl...@gmail.com] 
Sent: Monday, November 21, 2011 5:23 PM
To: Badjatya, Nikunj
Subject: Re: ProgressBar - Python and Powershell

WiX will manage all the progress bar stuff for you.

Just wrap it all in

On Mon, Nov 21, 2011 at 9:44 PM,   wrote:
> Yes I am executing powershell commands into virtual machines.
>
> Will have a look at WiX.
>
> But please, Answer my questions:
>
>>> My questions are:
>>>
>>> 1.       Can I have a better shared mechanism between python and
>>> powershell.?  As I am using a file here. Reading + writing in python and
>>> writing only in powershell.  !
>>>
>>> 2.       Does this thread mechanism work.? I am yet to implement and test
>>> it.! :P What can be the possible shortfalls.?
>
> Thanks
> Nikunj
>
> -Original Message-
> From: Alec Taylor [mailto:alec.tayl...@gmail.com]
> Sent: Monday, November 21, 2011 11:59 AM
> To: Badjatya, Nikunj
> Cc: python-list@python.org
> Subject: Re: ProgressBar - Python and Powershell
>
> So you're executing Powershell commands into Virtual Machines?
>
> Add this into the installer (probably WiX is your best bet)
>
> On Mon, Nov 21, 2011 at 3:40 AM,   wrote:
>> Thanks for reply.
>> Python and Powershell are required because the installer would deal in 
>> virtual machines ( VMware environment ).
>> Some prechecks and postconfig are required in both VMware and Windows 
>> environment. For dealing with VMware environment powershell has the best 
>> bonding. For windows I am  using Python.
>>
>> I am new to this field and do not know if there is an alternative 
>> available.! Can you please suggest an alternative to Powershell in VM 
>> environment. ?
>>
>> The current look of the installer is completely command line based.
>>
>>
>> -Original Message-
>> From: Alec Taylor [mailto:alec.tayl...@gmail.com]
>> Sent: Sunday, November 20, 2011 7:22 PM
>> To: Badjatya, Nikunj
>> Cc: python-list@python.org
>> Subject: Re: ProgressBar - Python and Powershell
>>
>> Why are you writing an installer in Python and Powershell?
>>
>> Just write an installer in WiX, NSIS or Inno like the rest of the sane world.
>>
>> Alternatively take a look at MakeMSI or the script python uses to
>> generate there .MSI.
>>
>> Anything else is WAY too non-standard to consider.
>>
>> On Mon, Nov 21, 2011 at 12:01 AM,   wrote:
>>> Can anyone throw some light on this please ! ?
>>>
>>>
>>>
>>>
>>>
>>> From: python-list-bounces+nikunj.badjatya=emc@python.org
>>> [mailto:python-list-bounces+nikunj.badjatya=emc@python.org] On Behalf Of
>>> nikunj.badja...@emc.com
>>> Sent: Thursday, November 17, 2011 4:10 PM
>>> To: python-list@python.org
>>> Subject: ProgressBar - Python and Powershell
>>>
>>>
>>>
>>> Hi All,
>>>
>>>
>>>
>>> I am using Python 2.7, windows Env.
>>>
>>> I have an Installer written in Python(45%) and Powershell(55%) which is used
>>> to install Virtual Machines at specific locations. It is single threaded.
>>>
>>> I am trying to implement a ProgressBar  for this installer. So that the user
>>> will come to know the progress of the installation.
>>>
>>> I am using pypi progressbar module.
>>>
>>> The top script is in python which inturns calls powershell scripts using
>>> subprocess.call() and proceeds with the installation.
>>>
>>>
>>>
>>> I am taking a shared file between python and powershell, so that diff
>>> functions can update their %age completion level in to the file. Ex. Func1()
>>> updates it to 5%,  func2() will add its own 5% to it.. and so on.
>>>
>>> At the start of the (main.py) script I am creating a thread whose sole
>>> purpose would be to keep "READ" a temp file for a new entry in it.
>>>
>>> Based on this entry I can have my thread update the progressbar on the
>>> console.
>>>
>>>
>>>
>>> My questions are:
>>>
>>> 1.   Can I have a better shared mechanism between python and
>>> powershell.?  As I am using a file here. Reading + writing in python and
>>> writing only in powershell.  !
>>>
>>> 2.   Does this thread mechanism work.? I am yet to implement and test
>>> it.! :P What can be the possible shortfalls.?
>>>
>>>
>>>
>>>
>>> Thanks
>>>
>>>
>>>
>>> Nikunj
>>>
>>> Bangalore - India
>>>
>>>
>>>
>>>
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>>
>>
>

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


Format the ouput in my python code

2011-11-21 Thread sl33k
I am printing the numbers from 1 to 100. In that, I want to display
multiples of 3,5 and of both as mulof3, mul0f5 and mulof3and5
respectively.

 I am getting the output I want but I would like to format the output
to print only 10 number per line. How do I go about doing this?

for i in range(1, 101):
if i % 3 == 0:
if i % 5 == 0:
print 'mulof3and5',
else:
print 'mulof3',
elif i % 5 == 0:
print 'mulof5',
else:
print i

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


Re: Close as Many Files/External resourcs as possible in the face of exceptions

2011-11-21 Thread Mel Wilson
GZ wrote:
> Here is my situation. A parent object owns a list of files (or other
> objects with a close() method). The close() method can sometimes 
fail
> and raise an exception. When the parent object's close() method is
> called, it needs to close down as many files it owns as possible, 
even
> if the close() function of some files fail. I also want to re-raise 
at
> least one of the original exceptions so that the outer program can
> handle it.
[ ... ]
> 
> It will re-raise the first exception and preserve the context and
> close as many other files as possible while ignoring any further
> exceptions.
> 
> But this looks really awkward. And in the case that two files fail 
to
> close, I am not sure the best strategy is to ignore the second
> failure.

I imagine you could save any caught exception instances in a list and 
study them later.

Mel.

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


Re: Got some problems when using logging Filter

2011-11-21 Thread Jean-Michel Pichavant

sword wrote:

On Nov 16, 7:40 pm, Jean-Michel Pichavant 
wrote:
  

sword wrote:


The logging cookbook gives an Filter example, explainning how to add
contextural info to log. I can't figure out how to filter log from it.
  
Suppose I have 3 file, a.py, b.py and main.py

#file: a.py
import logging
  
logger=logging.getLogger(__name__)

def print_log():
logger.debug("I'm module a")
  
#file: b.py just like a.py

import logging
logger=logging.getLogger(__name__)
def print_log():
logger.debug("I'm module b")
  
#file: main.py

import logging
from logging import Filter
logging.basicConfig(level=logging.DEBUG)
logger=logging.getLogger("main")
logger.debug("This is main process")
logger.addFilter(Filter("a"))
  
And I expected that the console output would contain main and b module

log only. But it turned out that all logs there.  Is it the problem of
root logger?
  

Hi,

First of all, in the code you provided we can't see where you import a &
b, and when you call their respective print_log method.
Secondly,Filter("a") would allow only the "a" log events, not forbid
them. quoting the docs: "if name is specified, it names a logger which,
together with its children, will have its events allowed through the
filter."

As for your problem it may come from the fact that you applied the
filter to the 'main' logger, while you probably want to add the filter
to the *root* logger. Your current hierarchy is

root
  - main
  - a
  - b

events fired from 'a' will be handled by the root logger, not the main.
root = logging.getLogger()
root.addFilter('main')
root.addFilter('a')
root.addFilter('b')

JM



Thanks for your reply. I tried to edit the source a bit, now the
main.py looks like this:
#main.py
import logging
from logging import Filter
import a
import b

logging.basicConfig(level=logging.DEBUG)
root = logging.getLogger()
root.addFilter(Filter("GoneWithTheWind")) #so I suppose no log msg
would pass this filter

logger = logging.getLogger("main")
logger.debug("main process")
a.print_log()
b.print_log()


And It still prints out all the log msg. :(
  
You need to add you filter to the handler(s) of the root logger, not the 
root logger itself.


Filters to loggger object are applied only when the log event is raised, 
i.e. when one of the logging method error, info, warning, debug is called.
In your case, log events are raised by other loggers than the root 
logger, so its filter will not apply.


However any filter applied to the root *handlers* will be applied to any 
log processed by the handler, including log event raised by sub-logger.


root.handlers[-1].addFilter(Filter("GoneWithTheWind")) #so I suppose no log msg

JM

Quoting http://docs.python.org/library/logging.html#filter-objects

"Note that filters attached to handlers are consulted whenever an event is emitted 
by the handler, whereas filters attached to loggers are consulted whenever an event is 
logged to the handler (using debug(), info(), etc.) This means that events which have 
been generated by descendant loggers will not be filtered by a logger’s filter setting, 
unless the filter has also been applied to those descendant loggers."



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


RE: ProgressBar - Python and Powershell

2011-11-21 Thread Nikunj.Badjatya
Yes I am executing powershell commands into virtual machines.

Will have a look at WiX.

But please, Answer my questions:

>> My questions are:
>>
>> 1.   Can I have a better shared mechanism between python and
>> powershell.?  As I am using a file here. Reading + writing in python and
>> writing only in powershell.  !
>>
>> 2.   Does this thread mechanism work.? I am yet to implement and test
>> it.! :P What can be the possible shortfalls.?

Thanks
Nikunj

-Original Message-
From: Alec Taylor [mailto:alec.tayl...@gmail.com] 
Sent: Monday, November 21, 2011 11:59 AM
To: Badjatya, Nikunj
Cc: python-list@python.org
Subject: Re: ProgressBar - Python and Powershell

So you're executing Powershell commands into Virtual Machines?

Add this into the installer (probably WiX is your best bet)

On Mon, Nov 21, 2011 at 3:40 AM,   wrote:
> Thanks for reply.
> Python and Powershell are required because the installer would deal in 
> virtual machines ( VMware environment ).
> Some prechecks and postconfig are required in both VMware and Windows 
> environment. For dealing with VMware environment powershell has the best 
> bonding. For windows I am  using Python.
>
> I am new to this field and do not know if there is an alternative available.! 
> Can you please suggest an alternative to Powershell in VM environment. ?
>
> The current look of the installer is completely command line based.
>
>
> -Original Message-
> From: Alec Taylor [mailto:alec.tayl...@gmail.com]
> Sent: Sunday, November 20, 2011 7:22 PM
> To: Badjatya, Nikunj
> Cc: python-list@python.org
> Subject: Re: ProgressBar - Python and Powershell
>
> Why are you writing an installer in Python and Powershell?
>
> Just write an installer in WiX, NSIS or Inno like the rest of the sane world.
>
> Alternatively take a look at MakeMSI or the script python uses to
> generate there .MSI.
>
> Anything else is WAY too non-standard to consider.
>
> On Mon, Nov 21, 2011 at 12:01 AM,   wrote:
>> Can anyone throw some light on this please ! ?
>>
>>
>>
>>
>>
>> From: python-list-bounces+nikunj.badjatya=emc@python.org
>> [mailto:python-list-bounces+nikunj.badjatya=emc@python.org] On Behalf Of
>> nikunj.badja...@emc.com
>> Sent: Thursday, November 17, 2011 4:10 PM
>> To: python-list@python.org
>> Subject: ProgressBar - Python and Powershell
>>
>>
>>
>> Hi All,
>>
>>
>>
>> I am using Python 2.7, windows Env.
>>
>> I have an Installer written in Python(45%) and Powershell(55%) which is used
>> to install Virtual Machines at specific locations. It is single threaded.
>>
>> I am trying to implement a ProgressBar  for this installer. So that the user
>> will come to know the progress of the installation.
>>
>> I am using pypi progressbar module.
>>
>> The top script is in python which inturns calls powershell scripts using
>> subprocess.call() and proceeds with the installation.
>>
>>
>>
>> I am taking a shared file between python and powershell, so that diff
>> functions can update their %age completion level in to the file. Ex. Func1()
>> updates it to 5%,  func2() will add its own 5% to it.. and so on.
>>
>> At the start of the (main.py) script I am creating a thread whose sole
>> purpose would be to keep "READ" a temp file for a new entry in it.
>>
>> Based on this entry I can have my thread update the progressbar on the
>> console.
>>
>>
>>
>> My questions are:
>>
>> 1.   Can I have a better shared mechanism between python and
>> powershell.?  As I am using a file here. Reading + writing in python and
>> writing only in powershell.  !
>>
>> 2.   Does this thread mechanism work.? I am yet to implement and test
>> it.! :P What can be the possible shortfalls.?
>>
>>
>>
>>
>> Thanks
>>
>>
>>
>> Nikunj
>>
>> Bangalore - India
>>
>>
>>
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>

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


Re: Got some problems when using logging Filter

2011-11-21 Thread Vinay Sajip
On Nov 21, 7:15 am, sword  wrote:
>
> Thank you! Maybe I should find out another way to manipulate the log,
> like wrap the getLogger function and add the filter at the first
> time :)

If you are using Python 2.7, 3.2 or later, you can use dictionary-
based configuration - it's fairly painless.

http://docs.python.org/library/logging.config.html#logging.config.dictConfig

If you are using an earlier version of Python, the logutils project
includes the same dictionary-based configuration logic.

http://code.google.com/p/logutils/

Regards,

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


Re: (don't bash me too hard) Python interpreter in JavaScript

2011-11-21 Thread Alec Taylor
Just compile your python to C

:]

On Mon, Nov 21, 2011 at 6:41 PM, OKB (not okblacke)
 wrote:
> Carl Banks wrote:
>
>> Some people have already made an LLVM-to-Javascript compiler, and
>> have managed to build Python 2.7 with it.
>>
>> The LLVM-to-Javascript project is called emscripten.
>>
>> https://github.com/kripken/emscripten/wiki
>>
>> Demo of Python (and a bunch of other languages) here:
>>
>> http://repl.it/
>
>        Very interesting.  Is there a simple way to add third-party
> libraries to these?  I assume that for pure-Python modules you could
> just put a python file in the appropriate place and import it, but what
> about if you wanted a web app that used numpy or something?  Is that
> feasible?
>
> --
> --OKB (not okblacke)
> Brendan Barnwell
> "Do not follow where the path may lead.  Go, instead, where there is
> no path, and leave a trail."
>        --author unknown
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Close as Many Files/External resourcs as possible in the face of exceptions

2011-11-21 Thread Vincent Vande Vyvre


  
  
Le 21/11/11 06:46, GZ a écrit :

  Hi,

Here is my situation. A parent object owns a list of files (or other
objects with a close() method). The close() method can sometimes fail
and raise an exception. When the parent object's close() method is
called, it needs to close down as many files it owns as possible, even
if the close() function of some files fail. I also want to re-raise at
least one of the original exceptions so that the outer program can
handle it.

What I come up is something like this, suppose L is a list that holds
all the file objects.

is_closed = set()
try:
for f in L:
f.close()
is_closed.add(f)
except:
try:
raise #re-raise immediately, keeping context intact
finally:
for f in L: # close the rest of the file objects
if f not in is_closed:
 try:
 f.close()
 except:
  pass

It will re-raise the first exception and preserve the context and
close as many other files as possible while ignoring any further
exceptions.

But this looks really awkward. And in the case that two files fail to
close, I am not sure the best strategy is to ignore the second
failure.

What is a better way of handling such situation?

Thanks,
gz



Not tested

def close_all(L):
    is_not_closed = {}
    def close_(obj):
        try:
            obj.close()
        except Exception, why
            is_not_closed[obj] = why
    
    for f in L:
        close_(f)

Now, your dictionnary contain the file as key and the exception
message as value.

-- 
  Vincent V.V.
  Oqapy . Qarte+7 . PaQager
  


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


LFS 0.6 beta 1 released

2011-11-21 Thread Kai

Hi,

I'm happy to announce the release of LFS 0.6 beta 1.

LFS is an online shop based on Django and jQuery.

If you want to read more information please refer to:

http://www.getlfs.com/released-06-beta-1

Thanks
Kai


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