Re: Imaging libraries in active development?

2012-11-29 Thread Christian Heimes
Am 28.11.2012 22:11, schrieb Jorgen Grahn:
> I thought those formats were dead since about a decade?  (Ok, I know
> TIFF has niches, but JPEG 2000?)

Baseline TIFF is still used a lot when a lossless image format is
required. It's widely used for scientific stuff, long-time preservation,
health care (e.g. MRI) and for many more applications. If you need to
deal with formats like 32bit float RGBA or 128bit complex float pixels
or color spaces like CMYK, CIELUV, CIEXYZ, then TIFF is your man.

I'm sitting on nearly a quarter petabyte of TIFF images. The data should
still be usable in 200 years. Bit rot *is* a serious issue for long
periods of time.

> That seems like an argument for *not* having support for many file
> formats in the imaging library itself -- just pipeline into the best
> standalone utilities available.

An imaging library shouldn't implement all file formats on its own and
rather use existing libraries. That's what I'm doing with smc.freeimage.
It wraps and ties together FreeImage and lcms. FreeImage itself contains
and encapsulates eight libraries (e.g. libjpeg, libtiff4, libraw, libpng
...) in a powerful API.

Christian


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


Imaging library

2012-11-29 Thread zoom

C'mon guys, don't be so picky.
The point is that that he cannot find python library that can easily 
create HDR image or process RAW images (or some other image format).
Also, AFAIK there is no built in support for standard imaging filters, 
color space conversion, etc (as Alasdair also mentioned). One can do 
this with scipy, and this is how I do it. But I'm also interested if 
there is some library that implements any of those. IMHO it would be 
useful if one could code the same effects easily as clicking on the 
effect button in GIMP or Blender.
This is interesting question, and if any of you have any ideas on how 
this can be achieved, please share your knowledge with us.


P.S.
We do not need to tutor people about whether a RAW format is a specific 
image format or not (http://en.wikipedia.org/wiki/Raw_image_format) - we 
understand the point of his question albeit it is not clearly stated.
Assume good will - nobody is stating that PIL or scipy are bad, we 
simply ask whether there is something more out there.


It would be more useful if we would provide information on how to do it, 
or connect him with someone who can do it. Or point where he can request 
such feature or publish his solution. The policy not to implement every 
format under the sky is a legal one, but by implementing it one-by-one - 
together we might even get there.

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


Re: please help me to debud my local chat network program

2012-11-29 Thread Minh Dang
can anyone help me?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: please help me to debud my local chat network program

2012-11-29 Thread Chris Angelico
On Thu, Nov 29, 2012 at 8:03 PM, Minh Dang  wrote:
> can anyone help me?

Look over my previous posts. I've made several suggestions that you
haven't followed up on.

Also, check out ESR's article on asking questions, which I also linked
you to earlier. Take its advice. You'll help yourself, AND it'll be
easier for us to help you.

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


Re: os.popen and the subprocess module

2012-11-29 Thread Thomas Rachel

Am 27.11.2012 19:00 schrieb Andrew:


I'm looking into os.popen and the subprocess module, implementing
os.popen is easy but i hear it is depreciating however I'm finding the
implemantation of subprocess daunting can anyone help


This is only the first impression.

subprocess is much more powerful, but you don't need to use the full power.

For just executing and reading the data, you do not need much.

First step: create your object and performing the call:

sp = subprocess.Popen(['program', 'arg1', 'arg2'], stdout=subprocess.PIPE)

or

sp = subprocess.Popen('program arg1 arg2', shell=True, 
stdout=subprocess.PIPE)



The variant with shell=True is more os.popen()-like, but has security 
flaws (e.g., what happens if there are spaces or, even worse, ";"s in 
the command string?



Second step: Obtain output.

Here you either can do

stdout, stderr = sp.communicate()

can be used if the whole output fits into memory at once or you really 
have to deal with stderr or stdin additionally.


In other, simpler cases, it is possible to read from sp.stdout like from 
a file (with a for loop, with .read() or whatever you like).



Third step: Getting the status, terminating the process.

And if you have read the whole output, you do status = sp.wait() in 
order not to have a zombie process in your process table and to obtain 
the process status.



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


Re: Imaging libraries in active development?

2012-11-29 Thread Adrien

Hey Alasdair,

I believe OpenCV might do the trick for you:
- it contains everything you seem to need (+ much much more);
- it is efficient;
- it is cross-platform;
- it has a usable python interface since version 2.4;
- it is not going away any time soon and is constantly improved;
- it has an active user base.

But (there is always a but), it also has some issues:
- (the main one for me) documentation is often incomplete or even 
sometimes cryptic: the website (http://docs.opencv.org/) is great, but, 
IIRC, the docstrings are automatically generated from the C++ prototypes 
using Boost.Python; some trial & error is often necessary to find out 
what the parameters of a function should be;
- it may be overkill if you just want to do some basic image processing 
(maybe scikits-image is a better choice there?).


Hope this helps,

Adrien

Le 29/11/2012 07:53, Alasdair McAndrew a écrit :

I take your point that not being actively developed doesn't necessarily mean 
that the software is bad - but in general healthy software is continuously 
updated and expanded to meet the needs of its users, or to take advantage of 
new algorithms or hardware.

And in its current form PIL has a number of limitations: it doesn't allow 
linear filters of arbitrary size or shape, or non-linear filters (such as 
median filter) of arbitrary size. There doesn't seem to be built in support for 
standard imaging filters: Gaussian, Laplacian, LoG, edge detection, unsharp 
masking and so on.  It doesn't seem to have support for color space conversions 
(RGB, YIQ, HSV etc).  There don't seem to be standard edge detection routines 
(Laplacian of Gaussian, Canny, etc).  And so on.  Now maybe some of these can 
be found in other Python libraries, but I can't imagine I'm the only person who 
would ever want them in an imaging library.  Other libraries (scipy.ndimage, 
scikits-image) do go a long way to addressing my concerns.

Anyway, I was curious to know why PIL is lacking so much of what I would 
consider fairly fundamental imaging facilities, and why development seems to 
have stalled since 2009.

On Thursday, 29 November 2012 05:14:30 UTC+11, Michael Torrie  wrote:

On 11/28/2012 05:30 AM, Alasdair McAndrew wrote:


I'm investigating Python for image processing (having used Matlab,
then Octave for some years).  And I'm spoiled for choice: PIL and its
fork pillow, scipy.ndimage, scikits-image, mahotas, the Python
interface to openCV...
However, PIL doesn't seem to be in active development.  What I want
to know is - what are the current "standard" libraries for image
processing in Python which are in active development?
I have quite a few image processing student notes which I'm thinking
of converting to Python, but I'd like to use the most up-to-date
library.



I'm curious.  What features do you need that pil doesn't have?  Other

than updating pil to fix bugs, support new image types or new versions

of Python, what kind of active development do you think it needs to

have? Maybe pil has all the features the original author wanted and is

pretty stable.  To judge a package on how fast it's changing seems a bit

odd to me.  Obviously you want to know that bugs can get fixed of

course.  Perhaps none have been reported recently.


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


Re: re.search when used within an if/else fails

2012-11-29 Thread Duncan Booth
Dennis Lee Bieber  wrote:

>  Unless there has been a major change in the parser... (I still don't
> have Python 3.x installed)
> 
>  I believe  is expanded to 8-spaces -- NOT TO NEXT MULTIPLE OF
> 8...
> 

Certainly in Python 2.7 that's not the case: the tab expands to the next 
multiple of 8 spaces.

>>> if 1:
... print "yes" # space + tab
... print "no" # eight spaces
...
yes
no

If tab expanded to exactly 8 spaces the leading space would have forced an 
indentation error, but it didn't.

-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compare list entry from csv files

2012-11-29 Thread Anatoli Hristov
On Tue, Nov 27, 2012 at 9:41 PM, Neil Cerutti  wrote:
> On 2012-11-27, Anatoli Hristov  wrote:
>> Thank you all for the help, but I figured that out and the
>> program now works perfect. I would appreciate if you have some
>> notes about my script as I'm noob :) Here is the code:
>>
>> import csv
>>
>> origf = open('c:/Working/Test_phonebook.csv', 'rt')
>> secfile = open('c:/Working/phones.csv', 'rt')
>
> csv module expects files to be opened in binary mode in Python
> versions less than version 3.0. For Python versions >= 3.0, you
> use the special keyword argument, newlines='', instead.
>
>> phonelist = []
>> namelist = []
>
> The structure of your program is poor. It's workable for such a
> short script, and sometimes my first cuts are similar, but it's
> better to get out of the habit right away.
>
> Once you get this working the way you'd like you should clean up
> the structure as a service to your future self.
>
>> names = csv.reader(origf, delimiter=';')
>> phones = csv.reader(secfile, delimiter=';')
>
> You csv files don't seem to have header rows, but even so you can
> improve your code by providing fieldnames and using a DictReader
> instead.
>
> name_reader = csv.DictReader(origf, fieldnames=[
>  'Name', 'Blah', 'Phone#'])
>
> Then you can read from records with
>
>   name = row['Name']
>
> instead of using bare, undocumented integers.
>
>> for tel in phones:
>> phonelist.append(tel)
>>
>> def finder(name_row,rows):
>> for ex_phone in phonelist:
>> telstr = ex_phone[0].lower()
>> if telstr.find(name_row) >= 0:
>
> This strikes me as a crude way to match names. You don't really
> want Donald to match perfectly with McDonald, do you? Or for
> Smith to match with Smithfield?
>
> Yes, a human being will clean it up, but your program can do a
> better job.
>
>> print "\nName found: %s" % name_row
>> namelist[rows][-1] = ex_phone[-1].lower()
>> else:
>> pass
>> return
>>
>> def name_find():
>> rows = 0
>> for row in names:
>> namelist.append(row)
>> name_row = row[0].lower()
>> finder(name_row,rows)
>> rows = rows+1
>
> You can use the useful enumerate function instead of your own
> counter.
>
>   for rows, row in enumerate(names):
>
> ...though I would find 'rownum' or 'num' or just 'i' better than
> the name 'rows', which I find confusing.
>
>> name_find()
>> ofile  = open('c:/Working/ttest.csv', "wb")
>> writer = csv.writer(wfile, delimiter=';')
>> for insert in namelist:
>> writer.writerow(insert)
>> wfile.close()
>
> --
> Neil Cerutti
> --
> http://mail.python.org/mailman/listinfo/python-list

Hello,

Tried to document a little bit the script, but I'm not that good in that too :)

The only problem I have is that I cant compare other field than the
first one in
for ex_phone in phones:
telstr = ex_phone[0].lower()
When I use telstr = ex_phone[0].lower() it says out of range and the
strange think is that the range is 6 I can't figure that out. So when
I edit the csv I modify the look of the file and then I start the
script and it works, but I wanted to use more than one condition and I
can't :(




import csv

# Open the file with the names and addresses
origf = open('c:/Working/vpharma.csv', 'rt')
# Open the  file with the phone numbers
secfile = open('c:/Working/navori.csv', 'rt')

# Creates the empty list with the names
namelist = []
# Creates the empty list with the phone numbers
PHONELIST = []


# Reads the file with the names
# Format "Name","Phone"
names = csv.reader(origf, delimiter=';')

# Reads the file with the phone numbers
# Format "First name","Lastname","Address","City","Country","Phone"
phones = csv.reader(secfile, delimiter=';')

# Creates a list with phone numbers
#for tel in phones:
#PHONELIST.append(tel)


def finder(Compare_Name,rows):
'''
Compare the names from the namelist with the names from the phonelist.
If the name match - then the phone number is added to the specified field
'''
for ex_phone in phones:
telstr = ex_phone[0].lower()
print telstr
if telstr.find(Compare_Name) >= 0:
print "\nName found: %s" % Compare_Name
namelist[rows][-1] = ex_phone[-1].lower()
else:
print "Not found %s" % Compare_Name
pass
return

def name_find():
rows = 0
for row in names:
namelist.append(row)
Compare_Name = row[1].lower()
finder(Compare_Name,rows)
rows = rows+1

if __name__ == '__main__':
name_find()

# Writes the list to a file
wfile  = open('c:/Working/ttest.csv', "wb")
writer = csv.writer(wfile, delimiter=';')
for insert in namelist:
writer.writerow(insert)
wfile.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Migrate from Access 2010 / VBA

2012-11-29 Thread Nicolas Évrard
* Wolfgang Keller  [2012-11-25 20:48 +0100]: 

I am the lone developer of db apps at a company of 350+ employees.
Everything is done in MS Access 2010 and VBA. I'm frustrated with the
limitations of this platform and have been considering switching to
Python.

I've been experimenting with the language for a year or so,
and feel comfortable with the basics.

I am concerned that I'll have a hard time replacing the access form
and report designers. I've worked a little with TKinter, but it's a
far cry from the GUI designer in Access.


The list of Python frameworks for rapid development of desktop
(i.e. non-Web) database applications currently contains:

using PyQt (& Sqlalchemy):
Pypapi: www.pypapi.org
Camelot: www.python-camelot.com
Qtalchemy: www.qtalchemy.org

using PyGTK:
Sqlkit: sqlkit.argolinux.org (also uses Sqlalchemy)
Kiwi: www.async.com.br/projects/kiwi

using wxPython:
Dabo: www.dabodev.com
Defis: sourceforge.net/projects/defis (Russian only)
GNUe: www.gnuenterprise.org

Pypapi, Camelot, Sqlkit and Dabo seem to be the most active and best
documented/supported ones.


I'd like to add to the list 


 Tryton http://www.tryton.org/

Which framework can be used to create a business application without
even using the already existing modules (one of our customer uses only
the 'party' modules in order to manage insurance products, the GNU
Health (http://www.gnuhealth.org/) project uses more official modules
to create their HIS software).

Reporting is done through relatorio (http://relatorio.openhex.org/),
which uses ODF templates to generate ODF reports (or other format
thanks to unoconv) the client is written in GTk (we're writing one in
JavaScript right now (and I miss python badly)).

--
(°> Nicolas Évrard
( ) Liège
  `¯


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Imaging libraries in active development?

2012-11-29 Thread Alasdair McAndrew
Thanks for the heads-up about OpenCV.  I have in fact briefly looked at OpenCV 
(well, the documentation), and it does seem remarkably complete.  And what it 
doesn't provide, such as image transforms (FFT, DCT etc), are offered elsewhere 
by other Python libraries.

Probably the combinations of OpenCV, Scipy.ndimage and scikits-image would 
cover pretty much all of my needs.

Thanks,
Alasdair 
> Hey Alasdair,
> 
> 
> 
> I believe OpenCV might do the trick for you:
> 
> - it contains everything you seem to need (+ much much more);
> 
> - it is efficient;
> 
> - it is cross-platform;
> 
> - it has a usable python interface since version 2.4;
> 
> - it is not going away any time soon and is constantly improved;
> 
> - it has an active user base.
> 
> 
> 
> But (there is always a but), it also has some issues:
> 
> - (the main one for me) documentation is often incomplete or even 
> 
> sometimes cryptic: the website (http://docs.opencv.org/) is great, but, 
> 
> IIRC, the docstrings are automatically generated from the C++ prototypes 
> 
> using Boost.Python; some trial & error is often necessary to find out 
> 
> what the parameters of a function should be;
> 
> - it may be overkill if you just want to do some basic image processing 
> 
> (maybe scikits-image is a better choice there?).
> 
> 
> 
> Hope this helps,
> 
> 
> 
> Adrien
> 
> 
> 
> Le 29/11/2012 07:53, Alasdair McAndrew a écrit :
> 
> > I take your point that not being actively developed doesn't necessarily 
> > mean that the software is bad - but in general healthy software is 
> > continuously updated and expanded to meet the needs of its users, or to 
> > take advantage of new algorithms or hardware.
> 
> >
> 
> > And in its current form PIL has a number of limitations: it doesn't allow 
> > linear filters of arbitrary size or shape, or non-linear filters (such as 
> > median filter) of arbitrary size. There doesn't seem to be built in support 
> > for standard imaging filters: Gaussian, Laplacian, LoG, edge detection, 
> > unsharp masking and so on.  It doesn't seem to have support for color space 
> > conversions (RGB, YIQ, HSV etc).  There don't seem to be standard edge 
> > detection routines (Laplacian of Gaussian, Canny, etc).  And so on.  Now 
> > maybe some of these can be found in other Python libraries, but I can't 
> > imagine I'm the only person who would ever want them in an imaging library. 
> >  Other libraries (scipy.ndimage, scikits-image) do go a long way to 
> > addressing my concerns.
> 
> >
> 
> > Anyway, I was curious to know why PIL is lacking so much of what I would 
> > consider fairly fundamental imaging facilities, and why development seems 
> > to have stalled since 2009.
> 
> >
> 
> > On Thursday, 29 November 2012 05:14:30 UTC+11, Michael Torrie  wrote:
> 
> >> On 11/28/2012 05:30 AM, Alasdair McAndrew wrote:
> 
> >>
> 
> >>> I'm investigating Python for image processing (having used Matlab,
> 
> >>> then Octave for some years).  And I'm spoiled for choice: PIL and its
> 
> >>> fork pillow, scipy.ndimage, scikits-image, mahotas, the Python
> 
> >>> interface to openCV...
> 
> >>> However, PIL doesn't seem to be in active development.  What I want
> 
> >>> to know is - what are the current "standard" libraries for image
> 
> >>> processing in Python which are in active development?
> 
> >>> I have quite a few image processing student notes which I'm thinking
> 
> >>> of converting to Python, but I'd like to use the most up-to-date
> 
> >>> library.
> 
> >>
> 
> >>
> 
> >> I'm curious.  What features do you need that pil doesn't have?  Other
> 
> >>
> 
> >> than updating pil to fix bugs, support new image types or new versions
> 
> >>
> 
> >> of Python, what kind of active development do you think it needs to
> 
> >>
> 
> >> have? Maybe pil has all the features the original author wanted and is
> 
> >>
> 
> >> pretty stable.  To judge a package on how fast it's changing seems a bit
> 
> >>
> 
> >> odd to me.  Obviously you want to know that bugs can get fixed of
> 
> >>
> 
> >> course.  Perhaps none have been reported recently.

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


Re: 10 sec poll - please reply!

2012-11-29 Thread Michael Herrmann
Hey everyone,

this is my final mail. With all your help we have decided on names for our 
function. It was a surprisingly difficult process but your inputs helped 
tremendously. I have described our experiences (very good ones here, but 
somewhat mixed ones with StackOverflow) in a blog entry: 
http://www.getautoma.com/blog/New-version-of-Automa-with-improved-API

I will now stop spamming this list. Thank you so much again! If you're 
interested in how we're getting on in the future, do follow us on Twitter 
@BugFreeSoftware or on our blog http://www.getautoma.com/blog!

Thanks again, 
Michael
Co-founder and lead developer
@BugFreeSoftware
http://www.getautoma.com

On Tuesday, November 20, 2012 1:18:38 PM UTC+1, Michael Herrmann wrote:
> Hi, 
> 
> 
> 
> I'm developing a GUI Automation library (http://www.getautoma.com) and am 
> having difficulty picking a name for the function that simulates key strokes. 
> I currently have it as 'type' but that clashes with the built-in function. 
> Example uses of 'type': 
> 
> 
> 
> type(ENTER)
> 
> 
> 
> type("Hello World!")
> 
> 
> 
> type(CTRL + 'a')
> 
> 
> 
> What, in your view, would be the most intuitive alternative name?
> 
> 
> 
> Here are my thoughts so far: I could call it 'press' but then our GUI 
> automation tool also allows you to click things and then "press" might be 
> mistaken for "pressing a button". A less ambiguous alternative is "type_keys" 
> but that is rather long and doesn't read as well, for instance in 
> type_keys(ENTER).
> 
> 
> 
> Thank you very much!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it bad style to override the built-in function `type`?

2012-11-29 Thread Michael Herrmann
Hey everyone,

this is my final mail. With all your help we have decided on names for our 
function. It was a surprisingly difficult process but your inputs helped 
tremendously. I have described our experiences (very good ones here, but 
somewhat mixed ones with StackOverflow) in a blog entry: 
http://www.getautoma.com/blog/New-version-of-Automa-with-improved-API

I will now stop spamming this list. Thank you so much again! If you're 
interested in how we're getting on in the future, do follow us on Twitter 
@BugFreeSoftware or on our blog http://www.getautoma.com/blog!

Thanks again, 
Michael
Co-founder and lead developer
@BugFreeSoftware
http://www.getautoma.com

On Friday, November 23, 2012 5:12:39 PM UTC+1, Michael Herrmann wrote:
> Hi, 
> 
> 
> 
> do you think it's bad style to override the built-in function `type`? I'm 
> co-developing a GUI automation library called Automa 
> (http://www.getautoma.com) and 'type' would be a very fitting name for a 
> function that generates artificial key strokes. 
> 
> 
> 
> This post is motivated by an already lengthy discussion on this mailing list 
> (http://bit.ly/10aOy4H), where we tried to find alternative names for `type`. 
> Many were found, but none are quite as fitting as 'type'. 
> 
> 
> 
> For the sake of avoiding a discussion that is already being lead elsewhere 
> please confine this thread to what you generally think about overriding 
> `type`, and post suggestions for alternative names or solutions in the other 
> thread.
> 
> 
> 
> Thank you very much!
> 
> Michael
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compare list entry from csv files

2012-11-29 Thread Thomas Bach
Can you please cut the message you are responding to the relevant
parts?

On Thu, Nov 29, 2012 at 11:22:28AM +0100, Anatoli Hristov wrote:
> The only problem I have is that I cant compare other field than the
> first one in
> for ex_phone in phones:
> telstr = ex_phone[0].lower()
> When I use telstr = ex_phone[0].lower() it says out of range and the
> strange think is that the range is 6 I can't figure that out.

As I understood it phones is an csv.reader instance and you are
iterating repeatedly over it. But, csv.reader does not work this
way. You either have to reinstantiate phones with a fresh
file-descriptor (not so good) or cache the values in an appropriate
data structure (better) e.g. a list.

> import csv
> 
> # Open the file with the names and addresses
> origf = open('c:/Working/vpharma.csv', 'rt')
> # Open the  file with the phone numbers
> secfile = open('c:/Working/navori.csv', 'rt')

Note that you never close origf and secfile.

> […]
> # Reads the file with the phone numbers
> # Format "First name","Lastname","Address","City","Country","Phone"
> phones = csv.reader(secfile, delimiter=';')

So this should probably be
PHONES = list(csv.reader(secfile, delimiter=';'))

(in uppercase letters as it is a global)

> […]
> if __name__ == '__main__':
> name_find()
> 
> # Writes the list to a file
> wfile  = open('c:/Working/ttest.csv', "wb")
> writer = csv.writer(wfile, delimiter=';')
> for insert in namelist:
> writer.writerow(insert)
> wfile.close()

This should go either in the "if __name__ = …" part or in a function
on its own.

Also have a look at the with statement you can use it in several
places of your code.

There are several other improvements you can make:
+ instead of having the file-names hard coded try to use argparse to
  get them from the command-line,
+ let functions stand at their own and use less globals,
+ try to avoid the use of the type of the data structure in the name
  (e.g. names is IMHO a better name then namelist),
+ add tests.

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


Re: changing dicts in a threaded environment ?

2012-11-29 Thread Bart Thate
Terry !

thnx for replying, feedback is the thing i need ;] sorry for the late
reply, after your mail i have been coding like hurt (so many hours nonstop
hacking hurts in the chair). As i started with all the code in 1 file (what
i get when i think something is cool), i splitted the stuff up into proper
modules, so i can show that to explain what i am up to.

I come to this code a long time ago, during the programming of my previous
bots, where co coder maze introduced me to what he called a LazyDict. Dict
with dotted access for attributes instead of __getitem__, i like how the
code looks when dotted acces is used. While this contruct found its way
into my code, i had to deal with something different and this is "how to
adapt my data - storage - to changes in the code" problem.

All the databases i tried used some sort of schema to define the data and
onces that needs to change, reflection needed to take place to update the
storage of data. I need to be able to add attributes to objects without no
need to change or reflect anything. So i took the LazyDict and added json
dump and load functionality to it. This worked great in terms of
flexibility in the code, but load on it is very low, so not to be compared
with the scale etc that normal databases have to deal with. Soon i want to
add a .send(JID) to it so i can send a object via JSON to the other side
and have it reconstruct there. Kinda like Pyro based on JSON, been
experimenting with that with Aim during our endless "let's code a new
collective" attempts, where the "send the pickle over the wire" stuff was
not secure, the use of XML to make it secure made it a true bandwidth hog,
and parsing JSON is still considered secure, because no eval gets used when
deconstructing.

In first i am not interested in deconstructing objects from the JSON yet,
my first intention is to make a JSON dict replication system, where i can
put data in a dict, put JSON of that dict over the wire to various other
pieces of my software and have it possible to authenticate the correctness
of the data. This is because i want - eventually - to have my code run in a
device where the data it generates can be used as proof in a court of law.
This is to make some modern version of a diary, where one can register all
things happening during a period of time.

So i have to make this  1 LazyDict, JSON saveable and sendable etc, objects
thats is going to be the core of what i doing and i need to properly design
it and todo that properly i need feedback on it ;]

Thank for your feedback Terry, it is clear to me now that i need to do the
locking myself, thing is i need to have this object behave excactly as
normal standard object (dict in this case) so i want to know if there are
any pointers to docs that discuss the semantics of dicts esp. what needs to
be locked properly to ensure that there is only one accessor at the time.

Question to all of you is something like "if you want 1 basic type added to
python 4, what would it's semantics be ?"

See https://github.com/feedbackflow/life for the code i am working on now ;]

https://github.com/feedbackflow/life/blob/master/life/__init__.py - for the
big O class that is to become the core of it all, pun intended ;]

Looking forward to hear what you and all the others reading this are
thinking.

Bart, thinking of "what if i stored the JSON in git ?" and "would mercurial
then not be better" haha


p.s. code is not in a "good shape" yet, it is just that i would take too
long for me to respond and 20 hours work days are killing me to get this
right "the first time" ;]
p.s.s trbs your code is in the moment plugs are going to be added, need the
core solid first ;]


On Tue, Nov 27, 2012 at 8:18 PM, Terry Reedy  wrote:

> On 11/27/2012 7:53 AM, Bart Thate wrote:
>
> [Answers based on reading without thread experience.]
>
>
>  i use python3 now and i need to be able to remove elements from a dict
>> in a thread safe manner.
>>
>
> Essentially no change from py2.
>
>
>  kinda like a Queue.Queue thing but then in a dict, so i can pass arond
>>   my dict based objects as parameters arond without having to wonder if
>> it gets properly locked.
>>
>
> As I understand it, dicts do not get locked unless you do it.
>
>  So not only do i need to get this solved:
>>
>> Issue #14417 **: Mutating a dict during
>>
>> lookup now restarts the lookup instead of raising a RuntimeError (undoes
>> issue #14205 **).
>>
>
> As I understand #14417, you should be explicitly locking dicts. The issue
> in #14205 was that people doing mutations in just one thread and lookups in
> others usually got away without locking becuase of recursive retries, but
> occasionally crashed the interpreter because of them. The first fix was to
> prevent crashes by removing retries. But that would break programs that
> naively worked because of them. The second fix was to do iterative retries
> instead, so a thread might occasionally hang

[ANN] New article published: TMSTAF – The Extended Use of STAF on Test Automation

2012-11-29 Thread [email protected]
http://ojs.pythonpapers.org/index.php/tpp/article/view/247

Abstract

As software packages becomes increasingly large and complex, the time required 
for testing them, throughout the development lifecycle, has also increased. 
Because testing activities consume the majority of software Quality Assurance 
(QA) resources, a test platform was needed to speed up test cycles without any 
decrease in test result accuracy. The use of Python 2.6 scripting language to 
create a faster, automated testing platform is reported here. Trend Micro 
Software Testing Automation Framework (TMSTAF) was developed using Python 2.6, 
based on Software Testing Automation Framework (STAF), to improve automated 
testing. We found that TMSTAF not only decreased testing time, it provided 
faster process integration, test feedback, and improved overall software 
quality. Using the TMSTAF automation environment for development and execution 
is simple to set up. Test cases can be created for use in both manual and 
automated tasks, converted to automated scripts, and implemented with structur
 al and flexible mechanisms. Automation script pre-runs and debugging make 
troubleshooting more efficiently; TMSTAF test report data can be used to 
identify quality issues quickly. TMSTAF can be seamlessly integrated into the 
build release process, making it a smart option for software QA engineers.
-- 
http://mail.python.org/mailman/listinfo/python-list


weird isinstance/issubclass behavior?

2012-11-29 Thread lars van gemerden
Hi,

I have encountered some strange behavior of isinstance(/issubclass): depending 
on the import path used for classes i get different output, while the classes i 
compare are in the same file. 

Basically if i import a class as:

from mod1.mod2 import A

or:

from mod0.mod1.mod2 import A

which both result in importing the same class, a call to isinstance(inst, A) in 
another module can have a different output. In this module

print type(inst), A, isinstance(inst, A), issubclass(type(inst), A)

gives:

  False False

resp.

  True True

which seems somewhat logical, but in my case a strange gotcha. My question is:
Is this intended, inevitable or a bug?

Cheers, Lars

PS: this is somewhat simpler than the actual case i've encountered, and i 
haven't tested this exact case, but for now i hope this is enough to get some 
of your insight.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: weird isinstance/issubclass behavior?

2012-11-29 Thread Chris Angelico
On Fri, Nov 30, 2012 at 1:59 AM, lars van gemerden  wrote:
> Basically if i import a class as:
>
> from mod1.mod2 import A
>
> or:
>
> from mod0.mod1.mod2 import A
>
> which both result in importing the same class, a call to isinstance(inst, A) 
> in another module can have a different output.

What you may be seeing there is that you've imported the module twice.
There are two entirely separate module objects, taken from the same
file. Something instantiated from one class isn't an instance of the
other class even if they're indistinguishable classes; a little
monkeypatching might show you what's going on (fiddle with one class,
check the other, fiddle hasn't happened).

As a general rule, importing a module in different ways is considered
dangerous. Be consistent, and then this sort of oddity won't occur -
and you also won't have other oddities, eg with other global state.

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


Re: Migrate from Access 2010 / VBA

2012-11-29 Thread kagard
On Nov 27, 7:06 pm, David Bolen  wrote:
> kgard  writes:
> > I am the lone developer of db apps at a company of 350+
> > employees. Everything is done in MS Access 2010 and VBA. I'm
> > frustrated with the limitations of this platform and have been
> > considering switching to Python. I've been experimenting with the
> > language for a year or so, and feel comfortable with the basics.
> (...)
> > Has anyone here made this transition successfully? If so, could you
> > pass along your suggestions about how to do this as quickly and
> > painlessly as possible?
>
> I went through a very similar transition a few years ago from
> standalone Access databases (with GUI forms, queries and reports, as
> well as replication) to a pure web application with full reporting
> (albeit centrally designed and not a report designer for users).
>
> I suppose my best overall suggestion is to migrate the data first and
> independently of any other activities.  Unless your uses for Access in
> terms of GUI or reporting are extremely limited, don't try to replace
> your current system in one swoop, and in particular, be willing to
> continue allowing Access as long as necessary for GUI/reports until
> you're sure you've matched any current capabilities with an alternate
> approach.  For all its warts, as a database GUI and reporting tool,
> Access has a lot going for it, and it can be more complex than you may
> think to replicate elsewhere.
>
> So the first thing I would suggest is to plan and implement a
> migration of the data itself.  In my case I migrated the data from
> Access into PostgreSQL.  That process itself took some planning and
> testing in terms of moving the data, and then correcting various bits
> of the schemas and data types (if I recall, booleans didn't round-trip
> properly at first), so was actually a series of conversions until I
> was happy, during which time everyone was using Access as usual.
>
> To support the migration, I created a mirror Access database to the
> production version, but instead of local Jet tables, I linked all the
> tables to the PostgreSQL server. All other aspects of the Access
> database (e.g., forms, reports, queries) remained the same, just now
> working off of the remote data.  This needed testing too - for
> example, some multi-level joining in Access queries can be an issue.
> In some cases it was easier for me to migrate selected Access query
> logic into a database view and then replace the query in Access to use
> the view.  You also need to (painfully) set any UI aspects of the
> table definitions manually since the linking process doesn't set that
> up, for which I used the original Access db as a model.  I ended up doing
> that multiple times as I evolved the linked database, and I'll admit that
> was seriously tedious.
>
> While not required, I also wrapped up my new linked Access database
> into a simple installer (InnoSetup based in my case).  Prior to this
> everyone was just copying the mdb file around, but afterwards I had an
> installer they just ran to be sure they had the latest version.
>
> If you do this part carefully, for your end users, aside from
> installing the new database, they see absolutely no difference, but
> you now have easy central access to the data, and most importantly can
> write other applications and tools against it without touching the
> Access side.  It turns Access into just your GUI and reporting tool.
>
> If you have power users that make local changes they can continue to
> design additional queries or reports in their own local mdb against
> the linked tables.  They'll need some extra support for updates
> though, either instructions to re-link, or instructions on exporting
> and importing their local changes into a newly installed version of
> your master mdb.
>
> Having done this, you are then free to start implementing, for
> example, a web based application to start taking over functionality.
> The nice thing is that you need not replicate everything at once, you
> can start slow or with the most desirable features, letting Access
> continue to handle the less common or more grungy legacy stuff at
> first.  There are innumerable discussions on best web and application
> frameworks, so probably not worth getting into too much.  In my case
> I'm using a CherryPy/Genshi/SQLAlchemy/psycopg2 stack.
>
> As long as you still have Access around, you'll have to take it into
> consideration with schema changes, but that's not really that much
> harder than any other schema migration management.  It's just another
> client to the database you can run in parallel as long as you wish.
> If you do change the schema, when done, just load your master Access
> database, update the links, and rebuild/redistribute the installer to
> your users.  Many changes (e.g., new columns with defaults) can be
> backwards compatible and avoid forced upgrades.
>
> You can operate both systems in parallel for a while even for similar
> functionality (for test

Re: Migrate from Access 2010 / VBA

2012-11-29 Thread Joel Goldstick
On Thu, Nov 29, 2012 at 10:43 AM, kagard  wrote:

> On Nov 27, 7:06 pm, David Bolen  wrote:
> > kgard  writes:
> > > I am the lone developer of db apps at a company of 350+
> > > employees. Everything is done in MS Access 2010 and VBA. I'm
> > > frustrated with the limitations of this platform and have been
> > > considering switching to Python. I've been experimenting with the
> > > language for a year or so, and feel comfortable with the basics.
> > (...)
>
>
> > -- David
> >
> >
>
> Thanks, David, for all the helpful insights. I really appreciate the
> time you took to reply. Thanks to everyone who pitched in. You've
> given me a lot to think about.
>
> Keith
> --
> http://mail.python.org/mailman/listinfo/python-list
>


This looks promising:
http://www.codediesel.com/data/migrating-access-mdb-to-mysql/
-- 
Joel Goldstick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: weird isinstance/issubclass behavior?

2012-11-29 Thread lars van gemerden
On Thursday, November 29, 2012 3:59:37 PM UTC+1, lars van gemerden wrote:
> Hi,
> 
> 
> 
> I have encountered some strange behavior of isinstance(/issubclass): 
> depending on the import path used for classes i get different output, while 
> the classes i compare are in the same file. 
> 
> 
> 
> Basically if i import a class as:
> 
> 
> 
> from mod1.mod2 import A
> 
> 
> 
> or:
> 
> 
> 
> from mod0.mod1.mod2 import A
> 
> 
> 
> which both result in importing the same class, a call to isinstance(inst, A) 
> in another module can have a different output. In this module
> 
> 
> 
> print type(inst), A, isinstance(inst, A), issubclass(type(inst), A)
> 
> 
> 
> gives:
> 
> 
> 
>   False False
> 
> 
> 
> resp.
> 
> 
> 
>   True True
> 
> 
> 
> which seems somewhat logical, but in my case a strange gotcha. My question is:
> 
> Is this intended, inevitable or a bug?
> 
> 
> 
> Cheers, Lars
> 
> 
> 
> PS: this is somewhat simpler than the actual case i've encountered, and i 
> haven't tested this exact case, but for now i hope this is enough to get some 
> of your insight.

I know for sure that the imports both import the same file, though if i 
understand you correctly, it creates 2 different module objects? Are module 
object only created on an import statement?  

The 2 parameters of isinstance() follow a very different import path. 

Anyway, to not spend too much time us this, i'll just file it under 'dangerous' 
and use the second import statement. It does solve my problem. 

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


Re: Exponential arrival distribution in Python

2012-11-29 Thread duncan smith

On 28/11/12 21:34, Ricky wrote:


Hi all,

I am doing a project on traffic simulation. I want to introduce exponential 
arrival distribution to precede this task. Therefore I want write a code in 
python for exponential arrival distribution. I am very new for programming and 
if anybody can help me on this that would be great.

Cheers,
Ricky



Maybe you mean something like,

>>> from random import expovariate
>>> expovariate(1)
0.09133428954823608
>>> expovariate(1)
2.5388809393383407
>>>

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


Re: Weird import failure with "nosetests --processes=1"

2012-11-29 Thread Hans Mulder
On 29/11/12 04:13:57, Roy Smith wrote:
> I've got a minimal test script:
> 
> -
> $ cat test_foo.py
> import pyza.models
> print pyza.models
> 
> def test_foo():
> pass
> -
> 
> pyza.models is a package.  Under normal conditions, I can import it fine:
> 
> $ python
> Python 2.7.3 (default, Aug  1 2012, 05:14:39) 
> [GCC 4.6.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
 import pyza.models
 print pyza.models
>  '/home/roy/deploy/current/pyza/models/__init__.pyc'>

> 
> But when I run nosetests in parallel mode, the import fails in a way 
> which has me baffled.  What's going on here?
> 
> $ nosetests --processes=1 -s test_foo:test_foo
>  '/home/roy/deploy/current/pyza/models/__init__.pyc'>
> E
> ==
> ERROR: Failure: AttributeError ('module' object has no attribute 
> 'models')
> --
> Traceback (most recent call last):
>   File 
> "/home/roy/production/python/local/lib/python2.7/site-packages/nose/loade
> r.py", line 390, in loadTestsFromName
> addr.filename, addr.module)
>   File 
> "/home/roy/production/python/local/lib/python2.7/site-packages/nose/impor
> ter.py", line 39, in importFromPath
> return self.importFromDir(dir_path, fqname)
>   File 
> "/home/roy/production/python/local/lib/python2.7/site-packages/nose/impor
> ter.py", line 86, in importFromDir
> mod = load_module(part_fqname, fh, filename, desc)
>   File "/home/roy/songza/pyza/djapi/test_foo.py", line 2, in 
> print pyza.models
> AttributeError: 'module' object has no attribute 'models'
> 
> --
> Ran 1 test in 0.107s
> 
> FAILED (errors=1)


That is baffling indeed.  It looks like nose is adding some
directory to sys.path, which contains a module pyza.py instead
of a package.

One thing you could try, is changing line 2 of you script to just

print pyza

, to see if pyza is being loaded from
/home/roy/deploy/current/pyza/__init__.pyc, as you'd expect.  If it
isn't, you'll be
one step closer to a solution.

Another idea might be to delete all *.pyc files below
/home/roy/deploy/current/ and /home/roy/songza/pyza/djapi/.
That would help if a .pyc file is somehow out of sync with
the corresponding .py file.  That's not supposed to happen,
but if it does, you can get weird results.

One last idea: put these lines at the top of test_foo.py

import pdb
pdb.set_trace()

Running under nosetest should then drop you in the debugger.
Single step into the next statement ("import pyza.models") to
see where this gets you.  It should import pyza, and then
pyza.models.  Add some print statements to the __init__.py
files of those packages, so that there's somewhere for pdb
to stop and prompt.


Hope this helps,

-- HansM








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


Re: weird isinstance/issubclass behavior?

2012-11-29 Thread Ian Kelly
On Thu, Nov 29, 2012 at 9:07 AM, lars van gemerden wrote:

> > PS: this is somewhat simpler than the actual case i've encountered, and
> i haven't tested this exact case, but for now i hope this is enough to get
> some of your insight.
>
> I know for sure that the imports both import the same file, though if i
> understand you correctly, it creates 2 different module objects? Are module
> object only created on an import statement?
>
>
Yes, Python sees imports of two different absolute module paths and does
not recognize them as being the same file, so it imports each separately.
This scenario typically arises when your sys.path includes a folder that is
actually a module itself.  Recommended usage: don't do that.  Your sys.path
entries should contain modules and packages, not point inside them.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Migrate from Access 2010 / VBA

2012-11-29 Thread Michael Torrie
On 11/29/2012 09:05 AM, Joel Goldstick wrote:
> This looks promising:
> http://www.codediesel.com/data/migrating-access-mdb-to-mysql/

Unfortunately I have not found mdb tools to be sufficient.  You can use
them to convert the schema to sql, and to reveal any mdb password (great
for looking at the data structures of compiled apps), but it can't
handle all the data types properly.  To get data out of an mdb file, I
wrote a simple python program that used pyodbc to get the data.  pyodbc
implements a standard python db api interface.  I opened the access
database file with:


MDB = 'C:/Path/to/frs_or_mdb_file'
DRV = '{Microsoft Access Driver (*.mdb)}'
PWD = 'ifneeded'

conn = pyodbc.connect('DRIVER=%s;DBQ=%s;UID=admin;PWD=%s' % (DRV,MDB,PWD))

curs = conn.cursor()

Then you can run queries with standard python db abi calls in standard
SQL syntax, and it's pretty easy to pull out the data and insert it into
a MySQL or PostgreSQL database.

This is for python on Windows of course, and has to have Access
installed, or at least the access engine.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.popen and the subprocess module

2012-11-29 Thread Nobody
On Thu, 29 Nov 2012 10:09:44 +0100, Thomas Rachel wrote:

> The variant with shell=True is more os.popen()-like, but has security
> flaws (e.g., what happens if there are spaces or, even worse, ";"s in the
> command string?

I think that you're conflating the shell= option with whether the command
is a given as a list or a string.

Attempting to construct a command string risks introducing security flaws
(or other bugs). Wherever possible, the first argument should be a list. A
string should only be used if that's what you're given (e.g. via a
configuration file), in which case it should be used literally, without
any attempt to substitute filenames or other parameters.

On Windows, list-versus-string and shell= are orthogonal. A list will
always be converted to a string, as that's what the underlying
CreateProcess() function requires. shell=True prepends "cmd /c " ("cmd" is
replaced by the value of %comspec% if that is defined); this allows
execution of batch files, scripts, etc based upon their associations.

On Unix, passing a list with shell=True is rarely useful. It just prepends
['/bin/sh', '-c'] to the list, so the first item is the shell command
while subsequent items provide the values for the shell variables $1, $2,
etc.

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


Re: Imaging libraries in active development?

2012-11-29 Thread Nobody
On Wed, 28 Nov 2012 04:30:25 -0800, Alasdair McAndrew wrote:

> What I want to know is - what are the current "standard" libraries for
> image processing in Python which are in active development?

NumPy/SciPy.

PIL is fine for loading/saving image files (although if you're using a GUI
toolkit, that probably has its own equivalents). But for any non-trivial
processing, I normally end up using either NumPy or (if speed is an issue)
PyOpenGL/GLSL.

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


Few Issues on Parsing and Visualization

2012-11-29 Thread subhabangalore
Dear Group,

I am looking for some Python based Natural Language Tools.

(i)Parsers (either syntactic or semantic). NLTK has but there I have to input 
the grammar. I am looking for straight built in library like nltk tagging 
module.

(ii) I am looking for some ner extraction tools. NLTK has I am looking for 
another, pyner is there but could not download.

(iii) I am looking for relation extraction tool NLTK has but I am looking for 
another. 

(iv) I am looking for one information extraction library, I found GenSim but 
could not use it properly.

(v) I am looking for a visualization library, found networkx,matplotlib,vtk but 
I am looking for a visual analytics library.

I am looking all these tools for the use in Windows(XP/7) with Python2.6/2.7.

And if anyone can kindly let me know on how to use the Python binding of 
Stanford Parser.

Thanking in Advance,
Regards,
Subhabrata. 
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: weird isinstance/issubclass behavior?

2012-11-29 Thread Terry Reedy

On 11/29/2012 9:59 AM, lars van gemerden wrote:

Hi,

I have encountered some strange behavior of isinstance(/issubclass): depending 
on the import path used for classes i get different output, while the classes i 
compare are in the same file.

Basically if i import a class as:

 from mod1.mod2 import A
or:
 from mod0.mod1.mod2 import A

which both result in importing the same class,


As other said, both import the same abstract class but create two 
different concrete class objects.


> a call to isinstance(inst, A) in another module can have a different 
output.

In this module
 print type(inst), A, isinstance(inst, A), issubclass(type(inst), A)
gives:
   False False


Add print id(type(inst)), id(A) and you will see that they are different 
objects. The isinstance and issubclass calls compare the classes by 
identity (the default meaning of ==) and so False, False are correct.


--
Terry Jan Reedy

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


RE: re.search when used within an if/else fails

2012-11-29 Thread Prasad, Ramit
Ramit Prasad wrote:
> 
> Dennis Lee Bieber wrote:
> >
> > Unless there has been a major change in the parser... (I still don't
> > have Python 3.x installed)
> >
> > I believe  is expanded to 8-spaces -- NOT TO NEXT MULTIPLE OF
> > 8...
> 
> A tab is *one* character. Your *editor* may show tabs visually
> "expanded" or convert them to spaces. This is entirely editor dependent.
> My current (python) editor, does expands tabs to the next *multiple* of 4.
> It helps keep code aligned, and I have no need for 4 hard spaced tabs
> without regards to alignment (yet). I have had editors that did 4 hard
> spaced tabs, so it might be a developer/application preference.
> 
> >>> with open(r'c:\ramit\mix_tab_space.txt')as f:
> ... d = f.read()
> ...
> >>> print repr(d)
> '\tblah\ntest\n\t'
> >>> print d[0] + 'goo'
>   goo
> >>> print repr(d[0] + 'goo')
> '\tgoo'

Apologies, I missed that it was talking about the parser
and not editor/file. Please disregard my previous post. 


~Ramit


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


RE: Imaging libraries in active development?

2012-11-29 Thread Prasad, Ramit
Christian Heimes wrote:
> 
> Am 28.11.2012 19:14, schrieb Michael Torrie:
> > I'm curious.  What features do you need that pil doesn't have?  Other
> > than updating pil to fix bugs, support new image types or new versions
> > of Python, what kind of active development do you think it needs to
> > have? Maybe pil has all the features the original author wanted and is
> > pretty stable.  To judge a package on how fast it's changing seems a bit
> > odd to me.  Obviously you want to know that bugs can get fixed of
> > course.  Perhaps none have been reported recently.
> 
> PIL is missing a bunch of features like proper TIFF support (no
> multipage, g3/g4 compression and more), JPEG 2000, RAW and HDR image
> formats, tone mapping, proper ICC support, PEP 3128 buffer support ...
> 
> PIL is also rather slow. My smc.freeimage library can write JPEGs about
> six times faster, because it uses libjpeg-turbo. Only some Linux
> distributions have replaced libjpeg with the turbo implementation.
> 

Have you tried libtiff? I believe the author may read this list.
(He posted here for at least one release). 
http://code.google.com/p/pylibtiff/


Hope that helps,
Ramit


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


RE: re.search when used within an if/else fails

2012-11-29 Thread Prasad, Ramit
Dennis Lee Bieber wrote:
> 
>   Unless there has been a major change in the parser... (I still don't
> have Python 3.x installed)
> 
>   I believe  is expanded to 8-spaces -- NOT TO NEXT MULTIPLE OF
> 8...

A tab is *one* character. Your *editor* may show tabs visually 
"expanded" or convert them to spaces. This is entirely editor dependent. 
My current (python) editor, does expands tabs to the next *multiple* of 4. 
It helps keep code aligned, and I have no need for 4 hard spaced tabs 
without regards to alignment (yet). I have had editors that did 4 hard 
spaced tabs, so it might be a developer/application preference.

>>> with open(r'c:\ramit\mix_tab_space.txt')as f:
... d = f.read()
...
>>> print repr(d)
'\tblah\ntest\n\t'
>>> print d[0] + 'goo'
goo
>>> print repr(d[0] + 'goo')
'\tgoo'

> 
>   So the first is 8+4 => 12 spaces, the second is 2+8+4 => 14 spaces.
> 
>   Does 2 +  + 2 vs 4 +  vs  + 4 succeed? That would
> confirm the treatment.
> 
>   The main concern with mixed tab and spaces, as I recall, was due to
> having /editors/ and /terminals/ configured to show  as a four
> space (or anything other than an eight space) increment; so visually
> four spaces and one  might look the same... One user might have the
> editor showing 4-space indents on  but entering text using 4 spaces
> on input -- which now is mis-aligned if the source file HAD  in it.


~Ramit



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


RE: Compare list entry from csv files

2012-11-29 Thread Prasad, Ramit
Anatoli Hristov wrote:
> Hello,
> 
> Tried to document a little bit the script, but I'm not that good in that too 
> :)
> 
> The only problem I have is that I cant compare other field than the
> first one in
> for ex_phone in phones:
> telstr = ex_phone[0].lower()
> When I use telstr = ex_phone[0].lower() it says out of range and the
> strange think is that the range is 6 I can't figure that out. So when
> I edit the csv I modify the look of the file and then I start the
> script and it works, but I wanted to use more than one condition and I
> can't :(
> 
> 

Can you print ex_phone first. You are opening the files in text mode
so I wonder if the line endings are causing you to read and extra
"line" in between. Can you try reading the csv as "rb" instead of 
"rt"?

> 
> 
> import csv
> 
> # Open the file with the names and addresses
> origf = open('c:/Working/vpharma.csv', 'rt')
> # Open the  file with the phone numbers
> secfile = open('c:/Working/navori.csv', 'rt')
> 
> # Creates the empty list with the names
> namelist = []
> # Creates the empty list with the phone numbers
> PHONELIST = []
> 
> 
> # Reads the file with the names
> # Format "Name","Phone"
> names = csv.reader(origf, delimiter=';')
> 
> # Reads the file with the phone numbers
> # Format "First name","Lastname","Address","City","Country","Phone"
> phones = csv.reader(secfile, delimiter=';')
> 
> # Creates a list with phone numbers
> #for tel in phones:
> #PHONELIST.append(tel)
> 
> 
> def finder(Compare_Name,rows):
> '''
> Compare the names from the namelist with the names from the phonelist.
> If the name match - then the phone number is added to the specified field
> '''
> for ex_phone in phones:
> telstr = ex_phone[0].lower()
> print telstr
> if telstr.find(Compare_Name) >= 0:
> print "\nName found: %s" % Compare_Name
> namelist[rows][-1] = ex_phone[-1].lower()
> else:
> print "Not found %s" % Compare_Name
> pass
> return
> 
> def name_find():
> rows = 0
> for row in names:
> namelist.append(row)
> Compare_Name = row[1].lower()
> finder(Compare_Name,rows)
> rows = rows+1
> 
> if __name__ == '__main__':
> name_find()
> 
> # Writes the list to a file
> wfile  = open('c:/Working/ttest.csv', "wb")
> writer = csv.writer(wfile, delimiter=';')
> for insert in namelist:
> writer.writerow(insert)
> wfile.close()


~Ramit


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


Re: How to add CC and BCC while sending mails using python

2012-11-29 Thread akegb3
On Tuesday, September 30, 2008 8:00:16 AM UTC-8, Bernhard Walle wrote:
> Hi,
> 
> * cindy jones [2008-09-30 19:57]:
> >
> > Can someone tel me how to add cc's and bcc's while sending mails using
> > python
> 
> Following (tested) snippet should help:
> 
> -- 8< --
> from smtplib import SMTP
> from email.mime.image import MIMEImage
> from email.mime.text import MIMEText
> from email.mime.multipart import MIMEMultipart
> 
> to = '[email protected]'
> cc = '[email protected]'
> bcc = '[email protected]'
> 
> msg = MIMEMultipart()
> msg['To'] = to
> msg['Cc'] = cc
> msg['From'] = '[email protected]'
> msg['Subject'] = 'Test'
> text = MIMEText('Das ist ein Test')
> text.add_header("Content-Disposition", "inline")
> msg.attach(text)
> 
> s = SMTP('test.smtp.relay')
> s.sendmail(msg['From'], [to, cc, bcc], msg.as_string())
> s.quit()
> -- >8 --
> 
> 
> Regards,
> Bernhard

Hello Bernhard,

I've tried the above code and the bcc address does not receive the message, on 
the To & CC addresses receive it. 

Here are snippets from my code, perhaps something will stand out to you?

to = '[email protected]'
cc = '[email protected]'
bcc = '[email protected]'

msg = MIMEMultipart()
msg['To'] = to
msg['Cc'] = cc
msg['Subject'] = 'My Subject text here'
msg['From'] = '[email protected]'

smtp = SMTP("smtpserver")
smtp.ehlo()
smtp.sendmail(msg['From'], [to, cc, bcc], msg.as_string())

Thanks in advance..hope you're still out there!!
~Ed
-- 
http://mail.python.org/mailman/listinfo/python-list


ntlm authentication for urllib2

2012-11-29 Thread Jorge Alberto Diaz Orozco

Hi there:
I'm working with urllib2 to open some urls and grab some data. The url 
will be inserted by the user and my script will open it and parse the 
page for results.
the thing is I'm behind a ntlm proxy, and I've tried with a lot of 
things to authenticate but it still doesn't work at all.

I did some research and found pytho-ntlm but I'm not sure how to use it.


I wrote something like this and it still giving me an authentication error:
Can someone help me???

import urllib2
from HTTPNtlmAuthHandler import HTTPNtlmAuthHandler
url = 'http://url.i.want.to.parse'
user = u'DOMAIN\\myuser'
password = 'mypass'

passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, url, user , password)
auth_NTLM = HTTPNtlmAuthHandler(passman)
proxy_handler = urllib2.ProxyHandler({'http': 'http://10.0.0.1:8080'})

opener = urllib2.build_opener(proxy_handler, auth_NTLM)
urllib2.install_opener(opener)

response = urllib2.urlopen(url)

print 'done'
print(response.read())

10mo. ANIVERSARIO DE LA CREACION DE LA UNIVERSIDAD DE LAS CIENCIAS 
INFORMATICAS...
CONECTADOS AL FUTURO, CONECTADOS A LA REVOLUCION

http://www.uci.cu
http://www.facebook.com/universidad.uci
http://www.flickr.com/photos/universidad_uci
--
http://mail.python.org/mailman/listinfo/python-list


Re: Compare list entry from csv files

2012-11-29 Thread Dave Angel
On 11/29/2012 05:22 AM, Anatoli Hristov wrote:
> 
> Hello,
>
> Tried to document a little bit the script, but I'm not that good in that too 
> :)
>
> The only problem I have is that I cant compare other field than the
> first one in
> for ex_phone in phones:
> telstr = ex_phone[0].lower()
> When I use telstr = ex_phone[0].lower() it says out of range and the
> strange think is that the range is 6 I can't figure that out. So when
> I edit the csv I modify the look of the file and then I start the
> script and it works, but I wanted to use more than one condition and I
> can't :(
>
>
>
>
> import csv
>
> # Open the file with the names and addresses
> origf = open('c:/Working/vpharma.csv', 'rt')
> # Open the  file with the phone numbers
> secfile = open('c:/Working/navori.csv', 'rt')
>
> # Creates the empty list with the names
> namelist = []
> # Creates the empty list with the phone numbers
> PHONELIST = []
>
>
> # Reads the file with the names
> # Format "Name","Phone"
> names = csv.reader(origf, delimiter=';')
>
> # Reads the file with the phone numbers
> # Format "First name","Lastname","Address","City","Country","Phone"
> phones = csv.reader(secfile, delimiter=';')
>
> # Creates a list with phone numbers
> #for tel in phones:
> #PHONELIST.append(tel)
Without populating the PHONELIST here, you have a serious problem.  Why
is it commented out?

>
> def finder(Compare_Name,rows):
> '''
> Compare the names from the namelist with the names from the phonelist.
> If the name match - then the phone number is added to the specified field
> '''
> for ex_phone in phones:

You should be using PHONELIST here as well.  phones is a pseudo-file,
which can only be traversed once.  A list can be traversed as many times
as you like, which is quite a few in your code.

> telstr = ex_phone[0].lower()
> print telstr
> if telstr.find(Compare_Name) >= 0:
> print "\nName found: %s" % Compare_Name
> namelist[rows][-1] = ex_phone[-1].lower()
> else:
> print "Not found %s" % Compare_Name
> pass
> return
>
> def name_find():
> rows = 0
> for row in names:
> namelist.append(row)
> Compare_Name = row[1].lower()
> finder(Compare_Name,rows)
> rows = rows+1
>
> if __name__ == '__main__':
> name_find()
>
> # Writes the list to a file
> wfile  = open('c:/Working/ttest.csv', "wb")
> writer = csv.writer(wfile, delimiter=';')
> for insert in namelist:
> writer.writerow(insert)
> wfile.close()

As I said before, process both files into lists, one that you treat as
constant (and therefore capitalized) and the other containing the data
you intend to modify.

It'd be much cleaner if you did all that input file parsing stuff in one
function, returning only the lists.  Call it just before calling
name_find().  Similarly, the part you have at the end belongs in a
different function, called just after calling name_find().

There's lots of other stuff that should be cleaner, but you've ignored
nearly all the suggestions from various people.


-- 

DaveA

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


Re: Weird import failure with "nosetests --processes=1"

2012-11-29 Thread Roy Smith
In article <[email protected]>,
 Hans Mulder  wrote:

> That is baffling indeed.  It looks like nose is adding some
> directory to sys.path, which contains a module pyza.py instead
> of a package.

We finally figured it out.  As it turns out, that's pretty close.

> Another idea might be to delete all *.pyc files below
> /home/roy/deploy/current/ and /home/roy/songza/

I've got

sys.path.insert(0, '/home/roy/deploy/current')

in my virtualenv's usercustomize.py.  Also, though historical accident, 
I had (but don't any longer)

PYTHONPATH=/home/roy/songza

in my .profile.  And /home/roy/deploy/current is a symlink to 
/home/roy/songza!  So, I had two different paths to the same directory.  
Why this only showed up as a problem when running under nose in 
multiprocess mode, I have no clue.  And how it ended up thinking pyza 
was a module instead of a package, I also have no idea.

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


pyHook and time libraries

2012-11-29 Thread Doron
Hey, I'm tring to create a software that records the keyboard/mouse and sends 
email of the log every predetermined period.

I've manage to make the recorder and the auto-email sender, but I still can't 
make both of them work simultaneously.

Can someone help me with this please?
I thought about threading but again... It just sends blank mails without the 
logs.

Thanks alot ahead!
-- 
http://mail.python.org/mailman/listinfo/python-list