Re: Replace blanks with letter

2013-08-21 Thread eschneider92
Thanks. I am running into a bunch of problems with the following code, all of 
which are clear when running the program

import random
letters='abcdefg' 
blanks='_'*len(letters) 
print('type letters from a to g')
print(blanks)
for i in range(len(letters)):
if letters[i] in input(): 
blanks = blanks[:i] + letters[i] + blanks[i+1:]
print(blanks)

If anyone could post an example of how to correctly code this, I would 
appreciate it. I can't seem to figure it out.

I'll definitely heed Fabio's advice for future reference, but I don't think 
it's related to the problems I'm currently experiencing. If it is, and I'm just 
not getting it (most likely the case), please post an example of how to 
implement his code advice in doing what I wish to accomplish here.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to keep cookies when making http requests (Python 2.7)

2013-08-21 Thread Luca Cerone
> 
> I have used "cookielib" externally to "urllib2". It looks
> 
> like this:
> 
> from urllib2 import urlopen, Request
> 
> from cookielib import CookieJar
> cookies = CookieJar()
> 
> 
> 
> r = Request(...)
> 
> cookies.add_cookie_header(r) # set the cookies
> 
> R = urlopen(r, ...) # make the request
> 
> cookies.extract_cookies(R, r) # remember the new cookies

Hi Dieter,
thanks a lot for the help.
I am sorry but your code is not very clear to me.
It seems that you are setting some cookies,
but I can't understand how you use the ones that the site
sends to you when you perform the initial request.

Have you tried this code to check if this work?
If it works as intended can you explain a bit better
what it does exactly?

Thanks again!
Luca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Query

2013-08-21 Thread Steven D'Aprano
On Wed, 21 Aug 2013 14:50:20 +0800, chandan kumar wrote:

[...]
> 1.Difference between  def StartThread(self) and def __init__(self):

__init__ is a special method called automatically by Python when you 
create an instance. StartThread is a method that the author of the code 
(perhaps you?) wrote themselves. It has no special meaning in Python, it 
will do whatever it is programmed to do, but only if you call it.


> 2   instance = Test() ,when this is called ,the code flow goes inside 
> the threading module , But 
>      instance1= Test1() ,the code flow goes inside the class Test1
>      When we call the both classes in same way ,How does the flow is 
> different for both.


When Test() is called, a new Test instance is created, and the __init__ 
method is called, but the thread is not started.

When you call Test1(), the __init___ method automatically starts the 
thread, because it includes the line "self.start()".

(Although, in the code you show, the indentation is wrong and the code 
will not work correctly. Please be more careful in the future about the 
indentation.)


> 3. Lets say self is passed explicitly for all the methods Like
>     def method1(self)
>          method2()

That won't work, you need to say self.method2()


>    def  method2(self):
>          method3()
>    def method(self)
>         method4()
>    def method4(self)
>
> What does self holds in method4 ,Is it self argument from method1?
> Sorry i'm confused with self argument.Please clarify if its valid
> question.

Yes, it is the same "self" all the way through. If you have ordinary 
functions:

def f1(x):
f2(x)

def f2(y):
f3(y)

def f3(z):
print z

and you call f1("something"), then the result will be to print 
"something". Even though the argument name is different, the same 
argument is passed from one function to the next.

Methods are exactly the same, except that the "self" argument is nearly 
always called "self".

When you have an instance, and you call one of its methods:

instance = SomeClass()
instance.method(extra, args)

then Python automatically uses the instance as the "self" argument. This 
is equivalent to:

SomeClass.method(instance, extra, args)
# inside the method, self=instance


except Python does it for you, instead of you needing to write it out in 
full like that. 



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


Re: refresing the edited python function

2013-08-21 Thread Sudheer Joseph


Thank you,
    But I wish if there was a foolproof reload
with best regards,
Sudheer

- Original Message -
> From: Jean-Michel Pichavant 
> To: Sudheer Joseph 
> Cc: python-list@python.org
> Sent: Tuesday, 20 August 2013 10:07 PM
> Subject: Re: refresing the edited python function
> 
> 
> - Original Message - 
> 
>>  Hi,
>>  I have been using ipython and ipython with qtconsole and working on a
>>  code with functions. Each time I make a modification in function
> 
>>  I have to quit IPTHON console (in both with and with out qt console )
>>  and reload the function freshly. If I need to see the changed I made
>>  in the function. I tried below options
>>  del function name
> 
>>  import the module again by issuing "from xxx.py import yy"
>>  import xxx.py
>>  make changes
>>  reload(xxx.py)
>>  this works only if the the function in the code has same name as the
>>  code. But even this do not reflect the changes made by editing the
>>  code.
>>  So what is the standard way to update the function for further tests
>>  after an edit?
>>  with best regards,
>>  Sudheer
> 
> Hi,
> 
> My "standard" way ;) :
> 1/ create a file
> 2/ edit the code
> 3/ run ipython (with %pdb on)
> 4/ within ipython "run myfile.py"
> 5/ check / introspect /debug
> 6/ change the code
> 7/ exit ipython
> 8/ reenter ipython
> 9/ using the ipython shell history, reexecute the file (2 key press) and go 
> back 
> to 5/
> 
> I used to reload my objects, it's been useful until one time when I lost a 
> lot of time because of some nasty side effect. In the end it's not worth it. 
> Always quit the shell, always.
> 
> JM
> 
> 
> 
> -- IMPORTANT NOTICE: 
> 
> The contents of this email and any attachments are confidential and may also 
> be 
> privileged. If you are not the intended recipient, please notify the sender 
> immediately and do not disclose the contents to any other person, use it for 
> any 
> purpose, or store or copy the information in any medium. Thank you.
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to keep cookies when making http requests (Python 2.7)

2013-08-21 Thread Fábio Santos
On 21 Aug 2013 09:22, "Luca Cerone"  wrote:
>
> >
> > I have used "cookielib" externally to "urllib2". It looks
> >
> > like this:
> >
> > from urllib2 import urlopen, Request
> >
> > from cookielib import CookieJar
> > cookies = CookieJar()
> >
> > 
> >
> > r = Request(...)
> >
> > cookies.add_cookie_header(r) # set the cookies
> >
> > R = urlopen(r, ...) # make the request
> >
> > cookies.extract_cookies(R, r) # remember the new cookies
>
> Hi Dieter,
> thanks a lot for the help.
> I am sorry but your code is not very clear to me.
> It seems that you are setting some cookies,
> but I can't understand how you use the ones that the site
> sends to you when you perform the initial request.

This example does both. The cookie jar adds the cookies to the http request
to be sent to the server, and updates the cookies from the response, if any
were sent. It seems pretty clear, seeing that it has a lot of comments.

The cookies from the site are thus in the cookie jar object after the call
to extract_cookies() extracts them from the response.

> Have you tried this code to check if this work?
> If it works as intended can you explain a bit better
> what it does exactly?

You should really test this yourself ;)

> Thanks again!
> Luca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Query

2013-08-21 Thread Ulrich Eckhardt

Am 21.08.2013 08:50, schrieb chandan kumar:

class Test(threading.Thread):
   def StartThread(self):
Lock = threading.Lock()
 self.start()


Inconsistently indented code, this is a killer for Python. Please read 
PEP8 and use four spaces! That said, there is never a need for deriving 
from the Thread class, you can also use it to run a function without 
that. That way is IMHO clearer because the threading.Thread instance is 
not the thread, just like a File instance is not a file. Both just 
represent handles for manipulating the actual thing.


Further, you have a local variable called "Lock" here (should be 
lowercase, see PEP 8) that you don't use. This is either a bug you 
missed or at least code that you didn't trim in order to produce a 
minimal example.




class Test1(threading.Thread):
 def __init__(self):
 threading.Thread.__init__ ( self )


Check out the "super()" syntax.



1.Difference between  def StartThread(self) and def __init__(self):


__init__ is a special function that gets called automatically. Search 
online for the documentation and or further explanations.




3. Lets say self is passed explicitly for all the methods Like
 def method1(self)
  method2()
def  method2(self):
  method3()
def method(self)
 method4()
def method4(self)
What does self holds in method4 ,Is it self argument from method1?
Sorry i'm confused with self argument.


"self" is just a name like others, only that it is customarily used for 
the first parameter of memberfunctions, i.e. for the instance of the 
according class. That said, above seven lines don't really serve to 
illustrate anything, because they are far from valid Python code.


I think before tackling threading, you should first go through some 
tutorials and documentation. I'd start with http://docs.python.org 
and/or do some online searches.


Good luck!

Uli

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


Re: Replace blanks with letter

2013-08-21 Thread Chris Angelico
On Wed, Aug 21, 2013 at 5:49 PM,   wrote:
> Thanks. I am running into a bunch of problems with the following code, all of 
> which are clear when running the program


Some of us don't have time to just execute arbitrary code in some safe
environment, so we'd REALLY rather you paste in the exception
traceback (if it's throwing one), or explain what it ought to be doing
that it isn't doing, or in whatever other way show what the problems
actually are. Remember, what's obvious to you isn't obvious to us;
what you see as an obvious problem might actually be correct
behaviour, so without knowing your expectations, we can't pinpoint the
trouble.

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


Matrix sort

2013-08-21 Thread vijayendramunikoti
Hi
I have a matrix of numbers representing the nodal points as follows:

Element No.Nodes

1 1 2 3 4
2 5 6 7 8
3 2 3 9 10
...
...
x 9 10 11 12
...

so this is a matrix of numbers 4 x n
Elements 1 and 3 are neighbours (as they share nodes 2 3). Similarly elements 3 
and x are neighbours (they share nodes 9 and 10). I want to sort the matrix in 
such a way all the elements are sequentially arranged. How could I script it? 
can any one help me?
Thanks!
Vijayendra   
-- 
http://mail.python.org/mailman/listinfo/python-list


How to change scrollbar color in pygtk ?

2013-08-21 Thread Norah Jones
Hi, 

I Tried the below code, the color is not reflected, Am i missing something?

#add description box beside test cases
testCaseDescWindow = gtk.ScrolledWindow()
testCaseDescWindow.set_policy(gtk.POLICY_AUTOMATIC, 
gtk.POLICY_AUTOMATIC)

testCaseDescWindow.get_vscrollbar().modify_fg(gtk.STATE_NORMAL,gtk.gdk.color_parse('#40515F'))

testCaseDescWindow.get_hscrollbar().modify_fg(gtk.STATE_NORMAL,gtk.gdk.color_parse('#40515F'))


Thanks,
Norah Jones


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


Re: default python os x

2013-08-21 Thread Cameron Simpson
On 20Aug2013 09:01, Uwe Rangs  wrote:
| Ah, I see. Thank you!

Please don't top post. Thanks.

| On 2013-08-20 05:39:56 +, Steven D'Aprano said:
| >alias python1.5='env -u PYTHONSTARTUP python1.5'

I should point out that -u is a GNU env feature. It is not portable,
and in particular OSX "env" does not have it.

A shell function can do the same though:

  py20() {
( unset PYTHONSTARTUP
  exec python2.0 ${1+"$@"}
)
  }

I've said py20 instead of python2.0 primarily because bash is a
bit... picky about function names and rejected the ".".

Cheers,
-- 
Cameron Simpson 

But pessimism IS realism!   - D.L.Bahr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Matrix sort

2013-08-21 Thread Oscar Benjamin
On 21 August 2013 10:24,   wrote:
> Hi
> I have a matrix of numbers representing the nodal points as follows:
>
> Element No.Nodes
>
> 1 1 2 3 4
> 2 5 6 7 8
> 3 2 3 9 10
> ...
> ...
> x 9 10 11 12
> ...
>
> so this is a matrix of numbers 4 x n
> Elements 1 and 3 are neighbours (as they share nodes 2 3). Similarly elements 
> 3 and x are neighbours (they share nodes 9 and 10). I want to sort the matrix 
> in such a way all the elements are sequentially arranged. How could I script 
> it? can any one help me?

I think you want a topological sort algorithm. See here:
http://en.wikipedia.org/wiki/Topological_sorting

Before that though you'll want to preprocess your matrix into a data
structure that allows you to easily find the elements adjacent to any
given element. A list of lists is one approach:

graph = [
[3], # nodes adjacent to element 1
[],  #  element 2
[1, x],  # element 3
...
[3]  # element x
]


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


Re: Replace blanks with letter

2013-08-21 Thread Dave Angel
eschneide...@comcast.net wrote:

> Thanks. I am running into a bunch of problems with the following code, all of 
> which are clear when running the program
>
> import random
> letters='abcdefg' 
> blanks='_'*len(letters) 
> print('type letters from a to g')
> print(blanks)
> for i in range(len(letters)):
> if letters[i] in input(): 
> blanks = blanks[:i] + letters[i] + blanks[i+1:]
> print(blanks)
>
> If anyone could post an example of how to correctly code this, I would 
> appreciate it. I can't seem to figure it out.
>
> I'll definitely heed Fabio's advice for future reference, but I don't think 
> it's related to the problems I'm currently experiencing. If it is, and I'm 
> just not getting it (most likely the case), please post an example of how to 
> implement his code advice in doing what I wish to accomplish here.

Nowhere have you told us just what the homework assignment was. 
Depending on the goal, this could be "fixed" in various ways.  As it
stands, you are asking the user 7 times to type in the letters from a to
g.  So long as he responds each time the same way, it'll gradually fill
in the letters from left to right, and end up with all seven showing.

In fact, it'll do that even if the user just types the particular single
letter you're asking for.  So in my last response below, I typed a
string that didn't have all 7, but it did have a g, so that was good
enough.

davea@think2:~/temppython$ python3.3 eric.py 
type letters from a to g
___
abcdefg
a__
abcdefg
ab_
abcdefg
abc
abcdefg
abcd___
abcdefg
abcde__
agcdbfe
abcdef_
aggecca
abcdefg
davea@think2:~/temppython$ 

Maybe the problem is that you don't tell the user whether he has
succeeded or not.  To tell that, just stick a test at the end, outside
the for-loop.

if blanks == letters:
print("Good job")
else:
print("You lose, run again, and guess what I wanted")

-- 
DaveA


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


Create an App with Python & Win $5000

2013-08-21 Thread yigit
Hi all,

JotForm just announced its developer contest with their newly released API with 
a grand prize of $5000 to the best app and $500 for other categories. The API 
library can be used with Python so you can create endless apps with it.

The deadline for the contest is September 24, 2013.

Apply to the contest from http://developers.jotform.com/competition/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Replace blanks with letter

2013-08-21 Thread John Gordon
In <89146bb1-fb60-4746-93e2-6cb59cfbc...@googlegroups.com> 
eschneide...@comcast.net writes:

> Thanks. I am running into a bunch of problems with the following code, all
> of which are clear when running the program

No, they're not clear.  We can see what the code does, obviously, but we
don't know what it's *supposed* to do.

-- 
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


I wonder if I would be able to collect data from such page using Python

2013-08-21 Thread Comment Holder
Hi,
I am totally new to Python. I noticed that there are many videos showing how to 
collect data from Python, but I am not sure if I would be able to accomplish my 
goal using Python so I can start learning.

Here is the example of the target page:
http://and.medianewsonline.com/hello.html
In this example, there are 10 articles.

What I exactly need is to do the following:
1- Collect the article title, date, source, and contents.
2- I need to be able to export the final results to excel or a database client. 
That is, I need to have all of those specified in step 1 in one row, while each 
of them saved in separate column. For example:

Title1Date1   Source1   Contents1
Title2Date2   Source2   Contents2

I appreciate any advise regarding my case. 

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


Re: I wonder if I would be able to collect data from such page using Python

2013-08-21 Thread Joel Goldstick
On Wed, Aug 21, 2013 at 10:55 AM, Comment Holder
 wrote:
> Hi,
> I am totally new to Python. I noticed that there are many videos showing how 
> to collect data from Python, but I am not sure if I would be able to 
> accomplish my goal using Python so I can start learning.
>
> Here is the example of the target page:
> http://and.medianewsonline.com/hello.html
> In this example, there are 10 articles.
>
> What I exactly need is to do the following:
> 1- Collect the article title, date, source, and contents.
> 2- I need to be able to export the final results to excel or a database 
> client. That is, I need to have all of those specified in step 1 in one row, 
> while each of them saved in separate column. For example:
>
> Title1Date1   Source1   Contents1
> Title2Date2   Source2   Contents2
>
> I appreciate any advise regarding my case.
>
> Thanks & Regards//
> --
> http://mail.python.org/mailman/listinfo/python-list

I'm guessing that you are not only new to Python, but that you haven't
much experience in writing computer programs at all.  So, you need to
do that.  There is a good tutorial on the python site, and lots of
links to other resources.

then do this:

1. write code to access the page you require.  The Requests module can
help with that
2. write code to select the data you want.  The BeautifulSoup module
is excellent for this
3. write code to save your data in comma separated value format.
4. import to excel or wherever

Now, go off and write the code.  When you get stuck, copy and paste
the portion of the code that is giving you problems, along with the
traceback.  You can also get help at the python-tutor mailing list



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I wonder if I would be able to collect data from such page using Python

2013-08-21 Thread Comment Holder
Many thanks Joel,

You are right to some extent. I come from Finance background, but I am very 
familiar with what could be referred to as non-native languages such as Matlab, 
VBA,.. actually, I have developed couple of complete programs.

I have asked this question, because I am a little worried about the structure 
of this particular page, as there are no specific defined classes. 

I know how powerful Python is, but I wonder if it could do the job with this 
particular page.

Again, many thanks Joel, I appreciate your guidance.
All Best//
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I wonder if I would be able to collect data from such page using Python

2013-08-21 Thread Joel Goldstick
On Wed, Aug 21, 2013 at 11:44 AM, Comment Holder
 wrote:
> Many thanks Joel,
>
> You are right to some extent. I come from Finance background, but I am very 
> familiar with what could be referred to as non-native languages such as 
> Matlab, VBA,.. actually, I have developed couple of complete programs.
>
> I have asked this question, because I am a little worried about the structure 
> of this particular page, as there are no specific defined classes.
>
> I know how powerful Python is, but I wonder if it could do the job with this 
> particular page.
>
> Again, many thanks Joel, I appreciate your guidance.
> All Best//
> --
> http://mail.python.org/mailman/listinfo/python-list

Your biggest hurdle will be to get proficient with python.  Give
yourself a weekend with a good tutorial.  You won't be very skilled,
but you will get the gist of things.

Also, google Beautiful Soup.  You need the latest version. Its v4 I
think.  They have a GREAT tutorial.  Spend a few hours with it and you
will see your way to get the data you want from your web pages.

Since you gave a sample web page, I am guessing that you need to log
in to the site for 'real data'.  For that, you need to really
understand stuff that you might not.  At any rate, study the Requests
Module documentation.  Python comes with urllib, and urllib2 that
cover the same ground, but Requests is a lot simpler to understand

-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Unpickling data with classes from dynamic modules

2013-08-21 Thread Fredrik Tolf

Dear list,

I have a system in which I load modules dynamically every now and then 
(that is, creating a module with types.ModuleType, compiling the code for 
the module and then executing it in the module with exec()), and where I 
would wish to be able to have classes in those modules containing classes 
that could pickled, and then unpickled again.


The problem with that, currently, is of course two-fold: The dynamically 
loaded module may not be loaded at the time when the unpickling takes 
place, but even if it were, it isn't registered in sys.modules, so the 
unpickler can't find it either way. And, of course, that is detected 
already when pickling.


Is there any way to fix this, at all?

I considered trying to create subclasses of the pickler and unpickler that 
pickle a reference to a module loader and data for the particular module 
along with a class that comes from such a module, by overriding 
Pickler.save_global and Unpickler.load_global. Unfortunately, however, 
those functions aren't part of the public interface and can't be 
overridden when the C-pickle module is used instead (which, obviously, is 
what normally happens).


Is there any way around this without having to modify the pickle module 
itself?


--

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


A data transformation framework. A presentation inviting commentary.

2013-08-21 Thread F.R.

Hi all,

In an effort to do some serious cleaning up of a hopelessly cluttered 
working environment, I developed a modular data transformation system 
that pretty much stands. I am very pleased with it. I expect huge time 
savings. I would share it, if had a sense that there is an interest out 
there and would appreciate comments. Here's a description. I named the 
module TX:


The nucleus of the TX system is a Transformer class, a wrapper for any 
kind of transformation functionality. The Transformer takes input as 
calling argument and returns it transformed. This design allows the 
assembly of transformation chains, either nesting calls or better, using 
the class Chain, derived from 'Transformer' and 'list'. A Chain consists 
of a sequence of Transformers and is functionally equivalent to an 
individual Transformer. A high degree of modularity results: Chains 
nest. Another consequence is that many transformation tasks can be 
handled with a relatively modest library of a few basic prefabricated 
Transformers from which many different Chains can be assembled on the 
fly. A custom Transformer to bridge an eventual gap is quickly written 
and tested, because the task likely is trivial.
A good analogy of the TX methodology is a road map with towns 
scattered all over it and highways connecting them. To get from any town 
to any other one is a simple matter of hopping the towns in between. The 
TX equivalent of the towns are data formats, the equivalent of the 
highways are TX Transformers. They are not so much thought of in terms 
of what they do than in terms of the formats they take and give. 
Designing a library of Transformers is essentially a matter of 
establishing a collection of standard data formats. First the towns, 
then the highways.
A feature of the TX Transformer is that it retains both its input 
and output. This makes a Chain a breeze to build progressively, link by 
link, and also makes debugging easy: If a Chain doesn't work, Chain.show 
() reveals the failing link as the first one that has no output. It can 
be replaced with a corrected instance, as one would replace a blown 
fuse. Running the Chain again without input makes it have another try.
Parameter passing runs on a track that is completely separate from 
the payload track. Parameters can be set in order to configure a Chain 
prior to running it, or can be sent at runtime by individual 
Transformers to its siblings and their progeny. Parameters are keyed and 
get picked up by those Chain links whose set of pre-defined keys 
includes the parameter's key. Unintended pick-ups with coincidentally 
shared keys for unrelated parameters can be prevented by addressing 
parameters to individual Translators.


Below an application example. Five custom classes at the end exemplify 
the pattern. I join the post also as attachment, in case some 
auto-line-wrap messes up this text.


Commentary welcome

Frederic





An example of use: Download historic stock quotes from Yahoo Finance for 
a given range of dates and a list of symbols, delete a column and add 
three, insert the data in a MySQL table. Also write them to temporary 
files in tabular form for verification.
"make_quotes_writer ()" returns a custom transformation tree. 
"run_quotes ()" makes such a tree, sets it on a given time range and 
runs it on a list of symbols.
(Since Yahoo publishes the data for downloading, I presume it's 
okay to do it this way. This is a demo of TX, however, and should not be 
misconstrued as an encouragement to violate any publisher's terms of 
service.)



import TX, yahoo_historic_quotes as yhq

def make_quotes_writer ():

 Visualizer = TX.Chain (
  yhq.percent (),
  TX.Table_Maker (has_header = True),
  TX.Table_Writer (),
  name = 'Visualizer'
 )

 To_DB = TX.Chain (yhq.header_stripper(), TX.DB_Writer(table_name = 
'quotes'), name = 'To DB')


 To_File = TX.Chain (Visualizer, TX.File_Writer (), name = 'To File')

 Splitter = TX.Splitter (To_DB, To_File, name = 'Splitter')

 Quotes = TX.Chain (
  yhq.yahoo_quotes (),
  TX.CSV_To_List (delimiter = ','),
  TX.Numerizer (),
  yhq.wiggle_and_trend (),
  yhq.symbol (),
  Splitter,
  name = 'Quotes'
 )

 return Quotes


>>> Quotes = make_quotes_writer ()
>>> Quotes.show_tree()

Quotes
Quotes[0] - Yahoo Quotes
Quotes[1] - CSV To List
Quotes[2] - Numerizer
Quotes[3] - Wiggle and Trend
Quotes[4] - Symbol
Quotes[5] - Splitter
Quotes[5][0] - To DB
Quotes[5][0][0] - Header Stripper
Quotes[5][0][1] - DB Writer
Quotes[5][1] - To File
Quotes[5][1][0] - Visualizer
Quotes[5][1][0][0] - Percent
Quotes[5][1][0][1] - Table Maker
Quotes[5][1][0][2] - Table Writer
Quotes[5][1][1] - File Writer


def run_quotes (symbols, from_date = '1970-01-01', to_date = '2099-12-31'):
'''Downloads 

Re: refresing the edited python function

2013-08-21 Thread Piet van Oostrum
Dave Angel  writes:
>
> Seems to me your problem is with ipython's IDE, not with Python.  Python
> requires you to rerun your application when making most changes to code.
>  But it doesn't say anything about restarting a "console," whatever that
> is in this context.  I use Komodo IDE when i want an IDE functionality,
> and never restart Komodo, over hours of work.
>
IPython's IDE just works the way alex23 described. 
-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encapsulation unpythonic?

2013-08-21 Thread random832
On Mon, Aug 19, 2013, at 3:05, Steven D'Aprano wrote:
> In this toy example, both parties are at fault: the author of Parrot for 
> unnecessary data-hiding of something which is so obviously a useful piece 
> of information and should be part of the public interface,

It may wish to be notified when its name changes, and so have a name
property. The subclass may want to use a variable called _name for some
other purpose. (maybe "name" isn't the best example).

Examples often look pathological when you simplify out the bit that
makes them make sense.

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


Re: PEPs should be included with the documentation download

2013-08-21 Thread Chris Angelico
On Wed, Aug 21, 2013 at 3:14 PM, Aseem Bansal  wrote:
> Currently the documentation download includes a lot of things but PEPs are 
> not its part. I wanted to suggest that PEPs should be included in the 
> download. They are very much relevant to Python.

The PEPs are kinda like the specs that Python is built from, rather
than being end-user documentation; certainly most, if not all, are
unnecessary to most use of Python. There's really no point downloading
a whole pile of rejected PEPs as part of the crucial user-facing docs.

Also, how many people actually depend on the downloadable
documentation, rather than simply reading things online?

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


Re: I wonder if I would be able to collect data from such page using Python

2013-08-21 Thread Comment Holder
Dear Joel,

Many thanks for your help - I think I shall start with this way and see how it 
goes. My concerns were if the task can be accomplished with Python, and from 
your posts, I guess it can - so I shall give it a try :). 

Again, thanks a lot & all best//

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


Re: I wonder if I would be able to collect data from such page using Python

2013-08-21 Thread Joel Goldstick
On Wed, Aug 21, 2013 at 1:41 PM, Comment Holder  wrote:
> Dear Joel,
>
> Many thanks for your help - I think I shall start with this way and see how 
> it goes. My concerns were if the task can be accomplished with Python, and 
> from your posts, I guess it can - so I shall give it a try :).
>
> Again, thanks a lot & all best//
>
> --
> http://mail.python.org/mailman/listinfo/python-list


You're welcome.  One thought popped into my mind.  Since the site
seems to be from the Wall Street Journal, you may want to look into
whether they have an api for searching and retrieving articles.  If
they do, this would be simpler and probably safer than parsing web
pages.  From time to time, websites change their layout, which would
probably break your program.  However APIs are more stable

good luck to you
-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEPs should be included with the documentation download

2013-08-21 Thread random832
On Wed, Aug 21, 2013, at 13:32, Chris Angelico wrote:
> On Wed, Aug 21, 2013 at 3:14 PM, Aseem Bansal 
> wrote:
> > Currently the documentation download includes a lot of things but PEPs are 
> > not its part. I wanted to suggest that PEPs should be included in the 
> > download. They are very much relevant to Python.
> 
> The PEPs are kinda like the specs that Python is built from, rather
> than being end-user documentation; certainly most, if not all, are
> unnecessary to most use of Python. There's really no point downloading
> a whole pile of rejected PEPs as part of the crucial user-facing docs.
> 
> Also, how many people actually depend on the downloadable
> documentation, rather than simply reading things online?

If you've taken your laptop to somewhere there's no wi-fi, it's nice to
have offline help.

I think, though, that if there's any useful information that can be
obtained by reading accepted PEPs but not the documentation, or if
things are explained less clearly than in the PEPs, that's a bug in the
documentation, and should be remedied by adding to the documentation.
-- 
http://mail.python.org/mailman/listinfo/python-list


utcoffset v. _utcoffset

2013-08-21 Thread Skip Montanaro
Consider this little Python script:

import dateutil.parser
import pytz

x = dateutil.parser.parse("2013-08-16 23:00:00+01:00")
localtz = pytz.timezone("America/Chicago")
y = localtz.normalize(x)

When I execute it (Python 2.7.2, dateutil 1.5, pytz 2011h), I get this
traceback:

Traceback (most recent call last):
  File "/home/skipm/tmp/localtzex.py", line 8, in 
y = localtz.normalize(x)
  File "/opt/TWWfsw/python27p/lib/python2.7/site-packages/pytz/tzinfo.py",
line 233, in normalize
offset = dt.tzinfo._utcoffset
AttributeError: 'tzoffset' object has no attribute '_utcoffset'

Looking at the tzinfo attribute, I see that it has "utcoffset", but
not "_utcoffset".  I realize those are the latest, most up-to-datest
versions of all three elements.  I'm having trouble updating dateutil
and pytz on my Mac at home (stuck on even older versions).  Can
someone with newer versions of dateutil and pytz see if this problem
is still present?

Thx,

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


Re: PEPs should be included with the documentation download

2013-08-21 Thread Jerry Hill
On Wed, Aug 21, 2013 at 1:55 PM,   wrote:
> I think, though, that if there's any useful information that can be
> obtained by reading accepted PEPs but not the documentation, or if
> things are explained less clearly than in the PEPs, that's a bug in the
> documentation, and should be remedied by adding to the documentation.

Personally, the only PEPs I've used as reference material as PEP 8
(the Python Style Guide), and PEP 249 (the Python Database API
Specification v2.0).  If I recall correctly, one of the database
adapters I used basically said that they were PEP 249 compliant, and
didn't have much documentation beyond that.

It seems to me that adding the PEPs to the compiled documentation
would be a good thing.  They are at least as useful as the Language
Reference or the Embedding and Extending Python sections that are
already included.

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


Re: refresing the edited python function

2013-08-21 Thread Chris Angelico
On Wed, Aug 21, 2013 at 4:26 PM, Sudheer Joseph
 wrote:
>
>
> Thank you,
> But I wish if there was a foolproof reload
> with best regards,
> Sudheer

There isn't, any more than there's a foolproof way to prevent
top-posting. Some languages are designed to handle code reload; others
simply aren't. Python is one of the latter. And even when you're using
a language like Pike, you really have to design your application
around code reload; so it's a feature of specific apps (like MUDs)
that will be running for years on end without restarting, rather than
something that you want all the time. Otherwise, you run the risk of
having internal data structures and code out of sync - and if you're
not keeping anything significant from the previous run, then why are
you reloading code instead of restarting the app?

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


Re: PEPs should be included with the documentation download

2013-08-21 Thread random832
On Wed, Aug 21, 2013, at 14:15, Jerry Hill wrote:
> Personally, the only PEPs I've used as reference material as PEP 8
> (the Python Style Guide), and PEP 249 (the Python Database API
> Specification v2.0).  If I recall correctly, one of the database
> adapters I used basically said that they were PEP 249 compliant, and
> didn't have much documentation beyond that.

Maybe there should be documentation for PEP 249 and other such "API
Specifications" in the main documentation tree, in the same way that
.NET documents interfaces.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEPs should be included with the documentation download

2013-08-21 Thread Chris Angelico
On Thu, Aug 22, 2013 at 4:15 AM, Jerry Hill  wrote:
> On Wed, Aug 21, 2013 at 1:55 PM,   wrote:
>> I think, though, that if there's any useful information that can be
>> obtained by reading accepted PEPs but not the documentation, or if
>> things are explained less clearly than in the PEPs, that's a bug in the
>> documentation, and should be remedied by adding to the documentation.
>
> Personally, the only PEPs I've used as reference material as PEP 8
> (the Python Style Guide), and PEP 249 (the Python Database API
> Specification v2.0).  If I recall correctly, one of the database
> adapters I used basically said that they were PEP 249 compliant, and
> didn't have much documentation beyond that.
>
> It seems to me that adding the PEPs to the compiled documentation
> would be a good thing.  They are at least as useful as the Language
> Reference or the Embedding and Extending Python sections that are
> already included.

Ah, yes, there are a few that would be good. But I don't really see
that all the internally bits (PEP 393, anyone?) and rejected proposals
(PEP 315) need to be in the download. I wouldn't expect the full set
of RFCs to be included with the docs for the socket module, so I
equally don't expect the PEPs to be included.

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


Re: Basic Python Query

2013-08-21 Thread Johannes Bauer
On 21.08.2013 11:11, Ulrich Eckhardt wrote:

> That said, there is never a need for deriving
> from the Thread class, you can also use it to run a function without
> that. That way is IMHO clearer because the threading.Thread instance is
> not the thread, just like a File instance is not a file. Both just
> represent handles for manipulating the actual thing.

Huh? That I find most curious.

I *always* derive from threading.Thread and really like the way that
thread setup works (instanciate Thread handle, call start). Very
intuitive, never had the problems with clarity that you mentioned. Could
you elaborate on your suggestion? I don't seem to quite get it I'm afraid.

Best regards,
Johannes

-- 
>> Wo hattest Du das Beben nochmal GENAU vorhergesagt?
> Zumindest nicht öffentlich!
Ah, der neueste und bis heute genialste Streich unsere großen
Kosmologen: Die Geheim-Vorhersage.
 - Karl Kaos über Rüdiger Thomas in dsa 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A data transformation framework. A presentation inviting commentary.

2013-08-21 Thread Chris Angelico
On Thu, Aug 22, 2013 at 2:29 AM, F.R.  wrote:
> The nucleus of the TX system is a Transformer class, a wrapper for any kind
> of transformation functionality. The Transformer takes input as calling
> argument and returns it transformed.

Not to put too much of a damper on your concept, but it's seeming a
little over-engineered. Your description of a Transformer sounds to me
like simply... a function. It takes input, it returns something. Why
the heavy class-based interface?

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


Re: I wonder if I would be able to collect data from such page using Python

2013-08-21 Thread Terry Reedy

On 8/21/2013 1:52 PM, Joel Goldstick wrote:

On Wed, Aug 21, 2013 at 1:41 PM, Comment Holder  wrote:



Many thanks for your help - I think I shall start with this way and see how it 
goes. My concerns were if the task can be accomplished with Python, and from 
your posts, I guess it can - so I shall give it a try :).


CM: You still seem a bit doubtful. If you are wondering why no one else 
has answered, it is because Joel has given you a really good answer that 
cannot be beat without writing your code for you.



You're welcome.  One thought popped into my mind.  Since the site
seems to be from the Wall Street Journal, you may want to look into
whether they have an api for searching and retrieving articles.  If
they do, this would be simpler and probably safer than parsing web
pages.  From time to time, websites change their layout, which would
probably break your program.  However APIs are more stable


Including this suggestion, which I did not think of.

--
Terry Jan Reedy

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


Re: A data transformation framework. A presentation inviting commentary.

2013-08-21 Thread Terry Reedy

On 8/21/2013 12:29 PM, F.R. wrote:

Hi all,

In an effort to do some serious cleaning up of a hopelessly cluttered
working environment, I developed a modular data transformation system
that pretty much stands. I am very pleased with it. I expect huge time
savings. I would share it, if had a sense that there is an interest out
there and would appreciate comments. Here's a description. I named the
module TX:


You appear to have developed a framework for creating data flow 
networks. Others exists, including Python itself and things built on top 
of Python, like yours. I am not familiar with others built on Python, 
but I would not be surprised if your occupies its own niche. It is easy 
enough to share on PyPI.



The nucleus of the TX system is a Transformer class, a wrapper for any
kind of transformation functionality. The Transformer takes input as
calling argument and returns it transformed. This design allows the
assembly of transformation chains, either nesting calls or better, using
the class Chain, derived from 'Transformer' and 'list'.


Python 3 is built around iterables and iterators. Iterables generalize 
the notion of list to any structure that can be sequentially accessed. A 
collection can be either concrete, existing all at once in some memory, 
or abstract, with members created as needed.


One can think of there being two types of iterator. One merely presents 
the items of a collection one at a time. The other transforms items one 
at a time.


The advantage of 'lazy' collections' is that they scale up much better 
to processing, say, a billion items. If your framework keeps the input 
list and all intermediate lists, as you seem to say, then your framework 
is memory constrained. Python (mostly) shifted from list to iterables as 
the common data interchange type partly for this reason.


You are right that keeping data around can help debugging. Without that, 
each iterator must be properly tested if its operation is not transparent.


> A Chain consists

of a sequence of Transformers and is functionally equivalent to an
individual Transformer. A high degree of modularity results: Chains
nest.


Because iterators are also iterables, they nest. A transformer iterator 
does not care if its input is a concrete non-iterator iterable, a source 
iterator representing an abstract collection, or another transformer.


 Another consequence is that many transformation tasks can be

handled with a relatively modest library of a few basic prefabricated
Transformers from which many different Chains can be assembled on the
fly.


This is precisely the idea of the itertool modules. I suspect that 
itertools.tee is equivalent to Tx.split (from the deleted code). 
Application areas need more specialized iterators. There are many in 
various stdlib modules.



A custom Transformer to bridge an eventual gap is quickly written
and tested, because the task likely is trivial.


--
Terry Jan Reedy

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


Re: make elements of a list twice or more.

2013-08-21 Thread Tobiah
On 08/07/2013 01:50 AM, liuerfire Wang wrote:
> Sorry for the title which didn't make clear.
> 
> Here is a list x = [b, a, c] (a, b, c are elements of x. Each of them are 
> different type).  Now I wanna generate a new list as [b, 
> b, a, a, c, c].

If you don't care about the order, you can do:

x = x + x
-- 
http://mail.python.org/mailman/listinfo/python-list


Arpex Capital seleciona: Desenvolvedor Python (MongoDB) / SP

2013-08-21 Thread zughumancapital

Arpex Capital seleciona para uma de suas empresas:
Desenvolvedor Python (MongoDB)
Objetivo geral da Posição: Desenvolver software estável e de primeira linha, 
que será incorporado à plataforma de WiFi mais moderna atualmente.
Responsabilidades: escrever software que rodará tanto no backend (Python) 
quanto no frontend (HTML5).

Pré-requisitos:
- Conhecimento em Python, MongoDB
- Cloud computing, BigData
- Pensamento lógico e analítico
- Capacidade de absorver tecnologias novas de forma constante

Deveres:
- Escrever software sólido em Python

Formação:
Irrelevante (não cobramos) 

Local de Trabalho: São Paulo/SP

A empresa oferece remuneração compatível com o mercado + Benefícios.
Os interessados deverão enviar o CV para kgar...@arpexcapital.com.br , 
mencionando no assunto Desenvolvedor Python (MongoDB). 


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


Re: PEPs should be included with the documentation download

2013-08-21 Thread Terry Reedy

On 8/21/2013 1:32 PM, Chris Angelico wrote:

On Wed, Aug 21, 2013 at 3:14 PM, Aseem Bansal  wrote:

Currently the documentation download includes a lot of things but PEPs are not 
its part. I wanted to suggest that PEPs should be included in the download. 
They are very much relevant to Python.


The PEPs are kinda like the specs that Python is built from, rather
than being end-user documentation; certainly most, if not all, are
unnecessary to most use of Python. There's really no point downloading
a whole pile of rejected PEPs as part of the crucial user-facing docs.


The manuals are intended to document current reality. Accepted PEPs 
document plans, often minus details. They do not get updated to reflect 
the initial implementation, let alone subsequent changes. Thus even


There are a few chapters in the manual that reference a PEP, either 
because the details are though to be too esoteric for the manual or 
becuase no one has yet gotten around to rewriting the material for the 
manual. (In the latter case, a patch should be welcome.) So there might 
be a reason to include a '(Highly) Selected PEPs' heading to the main 
page. PEP 8 might be a candidate, though it was originally intended as 
an internal style guide for the stdlib only.


--
Terry Jan Reedy

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


RE: Unpickling data with classes from dynamic modules

2013-08-21 Thread Prasad, Ramit
Fredrik Tolf wrote:
> 
> Dear list,
> 
> I have a system in which I load modules dynamically every now and then
> (that is, creating a module with types.ModuleType, compiling the code for
> the module and then executing it in the module with exec()), and where I
> would wish to be able to have classes in those modules containing classes
> that could pickled, and then unpickled again.
> 
> The problem with that, currently, is of course two-fold: The dynamically
> loaded module may not be loaded at the time when the unpickling takes
> place, but even if it were, it isn't registered in sys.modules, so the
> unpickler can't find it either way. And, of course, that is detected
> already when pickling.
> 
> Is there any way to fix this, at all?
> 
> I considered trying to create subclasses of the pickler and unpickler that
> pickle a reference to a module loader and data for the particular module
> along with a class that comes from such a module, by overriding
> Pickler.save_global and Unpickler.load_global. Unfortunately, however,
> those functions aren't part of the public interface and can't be
> overridden when the C-pickle module is used instead (which, obviously, is
> what normally happens).
> 
> Is there any way around this without having to modify the pickle module
> itself?
> 
> --
> 
> Fredrik Tolf
> --

I believe rather than subclassing the pickler, you are expected to 
change the behavior from within the class via __getstate__ and __setstate__.

http://docs.python.org/2/library/pickle.html#object.__getstate__

Although, for your use case (loading unknown classes) the section on pickle and 
extension types may be more appropriate.

http://docs.python.org/2/library/pickle.html#pickling-and-unpickling-extension-types

Maybe all you need to add is implementation for obj.__reduce__


~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: utcoffset v. _utcoffset

2013-08-21 Thread Terry Reedy

On 8/21/2013 2:05 PM, Skip Montanaro wrote:

Consider this little Python script:

import dateutil.parser
import pytz


Neither of these are stdlib modules, so I cannot run this.


x = dateutil.parser.parse("2013-08-16 23:00:00+01:00")
localtz = pytz.timezone("America/Chicago")
y = localtz.normalize(x)

When I execute it (Python 2.7.2, dateutil 1.5, pytz 2011h), I get this
traceback:

Traceback (most recent call last):
   File "/home/skipm/tmp/localtzex.py", line 8, in 
 y = localtz.normalize(x)
   File "/opt/TWWfsw/python27p/lib/python2.7/site-packages/pytz/tzinfo.py",
line 233, in normalize
 offset = dt.tzinfo._utcoffset
AttributeError: 'tzoffset' object has no attribute '_utcoffset'

Looking at the tzinfo attribute, I see that it has "utcoffset", but
not "_utcoffset".  I realize those are the latest, most up-to-datest
versions of all three elements.  I'm having trouble updating dateutil
and pytz on my Mac at home (stuck on even older versions).  Can
someone with newer versions of dateutil and pytz see if this problem
is still present?


--
Terry Jan Reedy

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


Re: utcoffset v. _utcoffset

2013-08-21 Thread Ned Deily
In article 
,
 Skip Montanaro  wrote:

> Consider this little Python script:
> 
> import dateutil.parser
> import pytz
> 
> x = dateutil.parser.parse("2013-08-16 23:00:00+01:00")
> localtz = pytz.timezone("America/Chicago")
> y = localtz.normalize(x)
> 
> When I execute it (Python 2.7.2, dateutil 1.5, pytz 2011h), I get this
> traceback:
> 
> Traceback (most recent call last):
>   File "/home/skipm/tmp/localtzex.py", line 8, in 
> y = localtz.normalize(x)
>   File "/opt/TWWfsw/python27p/lib/python2.7/site-packages/pytz/tzinfo.py",
> line 233, in normalize
> offset = dt.tzinfo._utcoffset
> AttributeError: 'tzoffset' object has no attribute '_utcoffset'
> 
> Looking at the tzinfo attribute, I see that it has "utcoffset", but
> not "_utcoffset".  I realize those are the latest, most up-to-datest
> versions of all three elements.  I'm having trouble updating dateutil
> and pytz on my Mac at home (stuck on even older versions).  Can
> someone with newer versions of dateutil and pytz see if this problem
> is still present?

I believe the problem is that you are using them incorrectly.  
IAMNADatetimeExpert, but I think you are trying to normalize a 
non-tz-aware datetime object returned from dateutil.parser.parse.

-- 
 Ned Deily,
 n...@acm.org

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


Re: Raw_input with readline in a daemon thread makes terminal text disappear

2013-08-21 Thread David M. Welch
Hi all, 

This is an old thread, but I'm having the same behavior in my terminal when
I run some code but kill the process in the terminal (Ctrl-C).  The code has
two prime suspects (from a simple google search):
1. Creates ssh port forward via the subprocess module
(http://unix.stackexchange.com/questions/4740/screen-remote-login-failure-an
d-disappearing-text)
2. Using the getpass module (raw_input?)
Calling "$ reset" brings back the disappearing text, so I'm just wondering
if this issue has been addressed and if so, what should I be doing that I'm
not.

Thank you,
Dave W.
Response to post: 
http://mail.python.org/pipermail/python-list/2009-October/554784.html
I'm getting input for a program while it's running by using raw_input in a
loop in separate thread. This works except for the inconvenience of not
having 
a command history or the use of backspace etc.

That can be solved by loading the readline module; however, it results in a
loss of visible access to the terminal when the program ends: nothing is
echoed to the screen and the history is invisible (although it is there -
hitting return executes whatever should be there normally). The only way to
get it back is to close the terminal and open a new one.

Here is minimal code that reproduces the problem (python 2.5 on Linux):

from threading import Thread
import readline

get_input = Thread(target=raw_input)
get_input.setDaemon(True)
get_input.start()

If the thread is not set to daemon mode, there is no such problem (don't
know 
why this makes a difference), but in the real program, it needs to be a
daemon 
or it hangs the exit waiting for more input.

Any suggestions appreciated.

Thanks,

John


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


python3-sqlalchemy and debian repo

2013-08-21 Thread Mohsen Pahlevanzadeh
Dear all,

I want to use sqlalchemy library, When i use "apt-cashe search
sqlalchemy" , get the following result(part of result):
///
python-sqlalchemy - SQL toolkit and Object Relational Mapper for Python
python-sqlalchemy-doc - documentation for the SQLAlchemy Python library
python-sqlalchemy-ext - SQL toolkit and Object Relational Mapper for
Python - C extension
python3-sqlalchemy - SQL toolkit and Object Relational Mapper for Python
3


Question: I want to use python 3, So i didn't doc and ext suffix for
sqlalchemy compatiable with python 3. The given suffix removed in python
3 or merged in python3-sqlalchemy package? 

--mohsen



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


Re: NodeTransformer: how to remove nodes?

2013-08-21 Thread Tobias Müller
Thanks Chris and Peter.

I already went further along. No more issues so far.



2013/8/19 Peter Otten <__pete...@web.de>

> Tobias Müller wrote:
>
> > I'm facing an issue with NodeTransformer, a tool used for Python AST
> > manipulations.
> >
> > Last week I posted on stackoverflow.com, but there are no responses yet.
> > Maybe someone reading the mailing list can have a look and leave me a
> > response here or over there?
> >
> >
> http://stackoverflow.com/questions/18275662/python-nodetransformer-how-to-
> remove-nodes
>
> As Chris says, you are overriding too much of the generic behaviour. Here
> is
> a working demo:
>
> import ast
>
> class MyTransformer(ast.NodeTransformer):
> def visit_For(self, node):
> """
> For nodes: replace with nothing
> """
> print("removing a For node")
> return None
>
>
> source = """
> l = [0, 1, 2, 3]
>
> total = 0
>
> for i in l:
> total += i
>
> print(total)
> """
>
> transformer = MyTransformer()
> module = ast.parse(source)
> transformer.visit(module)
> codeobj = compile(module, '', 'exec')
> exec(codeobj)
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: utcoffset v. _utcoffset

2013-08-21 Thread Prasad, Ramit
Skip Montanaro wrote:
> 
> Consider this little Python script:
> 
> import dateutil.parser
> import pytz
> 
> x = dateutil.parser.parse("2013-08-16 23:00:00+01:00")
> localtz = pytz.timezone("America/Chicago")
> y = localtz.normalize(x)
> 
> When I execute it (Python 2.7.2, dateutil 1.5, pytz 2011h), I get this
> traceback:
> 
> Traceback (most recent call last):
>   File "/home/skipm/tmp/localtzex.py", line 8, in 
> y = localtz.normalize(x)
>   File "/opt/TWWfsw/python27p/lib/python2.7/site-packages/pytz/tzinfo.py",
> line 233, in normalize
> offset = dt.tzinfo._utcoffset
> AttributeError: 'tzoffset' object has no attribute '_utcoffset'
> 
> Looking at the tzinfo attribute, I see that it has "utcoffset", but
> not "_utcoffset".  I realize those are the latest, most up-to-datest
> versions of all three elements.  I'm having trouble updating dateutil
> and pytz on my Mac at home (stuck on even older versions).  Can
> someone with newer versions of dateutil and pytz see if this problem
> is still present?
> 
> Thx,
> 
> Skip
> --

Using Python 2.6, dateutil 1.5, pytz 2013b


Snipped from the documentation of pytz via help(localtz.normalize)
''' 
Correct the timezone information on the given datetime

If date arithmetic crosses DST boundaries, the tzinfo
is not magically adjusted. This method normalizes the
tzinfo to the correct one.
'''

Going from +1 to +6 will not cross the DST boundary.

The documentation for localtz.normalize (in pytz 2013b) has a sample 
of what to do if it does cross DST which seems to boil down to using 
datetime.astimezone() and then localtz.normalize() if your date 
arithmetic crosses DST.

>>> import dateutil.parser
>>> import pytz
>>> x = dateutil.parser.parse("2013-08-16 23:00:00+01:00")
>>> localtz = pytz.timezone("America/Chicago")
>>> x.astimezone( localtz )
datetime.datetime(2013, 8, 16, 17, 0, tzinfo=)


~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: Raw_input with readline in a daemon thread makes terminal text disappear

2013-08-21 Thread random832
On Wed, Aug 21, 2013, at 12:42, David M. Welch wrote:
> Hi all, 
> 
> This is an old thread, but I'm having the same behavior in my terminal
> when
> I run some code but kill the process in the terminal (Ctrl-C).  The code
> has
> two prime suspects (from a simple google search):
> 1. Creates ssh port forward via the subprocess module
> (http://unix.stackexchange.com/questions/4740/screen-remote-login-failure-an
> d-disappearing-text)
> 2. Using the getpass module (raw_input?)
> Calling "$ reset" brings back the disappearing text, so I'm just
> wondering
> if this issue has been addressed and if so, what should I be doing that
> I'm
> not.

Do you understand how tty modes (in particular, echo vs non-echo mode)
work?

What you've got is two different pieces of code (I think running
readline in two threads qualifies) fighting over the tty mode, and
probably one of them is turning echo mode off and then either never
restoring it because of how the program exits, or it gets into the
other's idea of the "original" mode.

Why does your program design require input to be handled in a thread
other than the main thread?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encapsulation unpythonic?

2013-08-21 Thread Ian Kelly
On Aug 21, 2013 10:53 AM,  wrote:
>
> On Mon, Aug 19, 2013, at 3:05, Steven D'Aprano wrote:
> > In this toy example, both parties are at fault: the author of Parrot for
> > unnecessary data-hiding of something which is so obviously a useful
piece
> > of information and should be part of the public interface,
>
> It may wish to be notified when its name changes, and so have a name
> property.

The example as given has no such property, and regardless of whether it is
a property or an attribute the public API should just be called "name".

> The subclass may want to use a variable called _name for some
> other purpose. (maybe "name" isn't the best example).

Probably not a good idea for multiple reasons if the base class already has
something called "name".
 On Aug 21, 2013 10:53 AM,  wrote:

> On Mon, Aug 19, 2013, at 3:05, Steven D'Aprano wrote:
> > In this toy example, both parties are at fault: the author of Parrot for
> > unnecessary data-hiding of something which is so obviously a useful piece
> > of information and should be part of the public interface,
>
> It may wish to be notified when its name changes, and so have a name
> property. The subclass may want to use a variable called _name for some
> other purpose. (maybe "name" isn't the best example).
>
> Examples often look pathological when you simplify out the bit that
> makes them make sense.
>
> --
> Random832
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Query

2013-08-21 Thread Fábio Santos
On 21 Aug 2013 20:07, "Johannes Bauer"  wrote:
>
> On 21.08.2013 11:11, Ulrich Eckhardt wrote:
>
> > That said, there is never a need for deriving
> > from the Thread class, you can also use it to run a function without
> > that. That way is IMHO clearer because the threading.Thread instance is
> > not the thread, just like a File instance is not a file. Both just
> > represent handles for manipulating the actual thing.
>
> Huh? That I find most curious.
>
> I *always* derive from threading.Thread and really like the way that
> thread setup works (instanciate Thread handle, call start). Very
> intuitive, never had the problems with clarity that you mentioned. Could
> you elaborate on your suggestion? I don't seem to quite get it I'm afraid.
>
> Best regards,
> Johannes

I cannot tell whether you are trolling or are just new to this, but you
don't always have to use threads. You use threads when you need multiple
parts of your program running concurrently. Don't inherit Thread if all you
are doing is a simple object with state, nor if your program does not need
concurrency.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Query

2013-08-21 Thread Ned Batchelder

On 8/21/13 6:50 PM, Fábio Santos wrote:



On 21 Aug 2013 20:07, "Johannes Bauer" > wrote:

>
> On 21.08.2013 11:11, Ulrich Eckhardt wrote:
>
> > That said, there is never a need for deriving
> > from the Thread class, you can also use it to run a function without
> > that. That way is IMHO clearer because the threading.Thread 
instance is

> > not the thread, just like a File instance is not a file. Both just
> > represent handles for manipulating the actual thing.
>
> Huh? That I find most curious.
>
> I *always* derive from threading.Thread and really like the way that
> thread setup works (instanciate Thread handle, call start). Very
> intuitive, never had the problems with clarity that you mentioned. Could
> you elaborate on your suggestion? I don't seem to quite get it I'm 
afraid.

>
> Best regards,
> Johannes

I cannot tell whether you are trolling or are just new to this, but 
you don't always have to use threads. You use threads when you need 
multiple parts of your program running concurrently. Don't inherit 
Thread if all you are doing is a simple object with state, nor if your 
program does not need concurrency.



I think it is safe to assume that Johannes meant, "when I use threads, I 
never do it the way you suggested, I always derive from threading.Thread."


--Ned.

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


Re: Encapsulation unpythonic?

2013-08-21 Thread Steven D'Aprano
On Wed, 21 Aug 2013 12:52:06 -0400, random832 wrote:

> On Mon, Aug 19, 2013, at 3:05, Steven D'Aprano wrote:
>> In this toy example, both parties are at fault: the author of Parrot
>> for unnecessary data-hiding of something which is so obviously a useful
>> piece of information and should be part of the public interface,
> 
> It may wish to be notified when its name changes, and so have a name
> property. The subclass may want to use a variable called _name for some
> other purpose. (maybe "name" isn't the best example).

Such a "name" property would be a public interface, and so a Good Thing. 
However, my toy example was of a case where something *obviously useful* 
was being left out of the public interface. If it were a public property, 
it wouldn't be the case that it were left out, would it?


> Examples often look pathological when you simplify out the bit that
> makes them make sense.

Naturally :-) 

I did call this a toy example. Nevertheless, in the Real World, data 
hiding can sometimes be a bit of a religion. Not all cases where people 
try various tricks and hacks to gain access to "private" and "protected" 
members are specious.

The whole Java getter and setter philosophy is based on the idea that 
everything, even the most innocuous data attribute, ought to be private, 
with a computed getter and setter Just In Case some day in the future you 
want to wrap access in code. In Python, you can turn an attribute into a 
computed property with no change to the public interface. In Java, you 
can't.


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


Using PyQT with QT Designer

2013-08-21 Thread Michael Staggs
I'm learning Python and I have a problem. I've asked the question everywhere 
and no one helps me, so I'm hoping someone here will. I am making a program 
that shows album covers and you click on the album cover in the top window. In 
the bottom window, the list of songs appear and you can click the individual 
song to play it. It's going to be a media player for children. I'm thinking 
I'll be able to use a dict and have the album as the key and the list of songs 
as the value to accomplish this.

Right now, I'm just using my picture directory to try and get the basic layout 
right. I designed a form in QT Designer: http://i.imgur.com/Wrp1zHW.png

Here is my gui file I got from running pyuic4 on the ui file:


# -*- coding: utf-8 -*-
 
# Form implementation generated from reading ui file 'window.ui'
#
# Created by: PyQt4 UI code generator 4.9.6
#
# WARNING! All changes made in this file will be lost!
 
from PyQt4 import QtCore, QtGui
 
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
 
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, 
_encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
 
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(800, 600)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.tableWidget = QtGui.QTableWidget(self.centralwidget)
self.tableWidget.setGeometry(QtCore.QRect(70, 20, 661, 381))
self.tableWidget.setObjectName(_fromUtf8("tableWidget"))
self.tableWidget.setColumnCount(0)
self.tableWidget.setRowCount(0)
self.listWidget = QtGui.QListWidget(self.centralwidget)
self.listWidget.setGeometry(QtCore.QRect(70, 400, 661, 181))
self.listWidget.setObjectName(_fromUtf8("listWidget"))
MainWindow.setCentralWidget(self.centralwidget)
 
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
 
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", 
None))

Now, according to websites I read, I should just have to add the following to 
my program to get it to use the form:

from window import Ui_MainWindow
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None, **kwargs):
super(MainWindow, self).__init__(parent)
self.setupUi(self)

and here is my program:

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from window import Ui_MainWindow
 
THUMBNAIL_SIZE = 128
SPACING= 10
IMAGES_PER_ROW = 5
 
class TableWidget(QTableWidget):
def __init__(self, parent=None, **kwargs):
QTableWidget.__init__(self, parent, **kwargs)
 
self.setIconSize(QSize(128,128))
self.setColumnCount(IMAGES_PER_ROW)
self.setGridStyle(Qt.NoPen)
 
# Set the default column width and hide the header
self.verticalHeader().setDefaultSectionSize(THUMBNAIL_SIZE+SPACING)
self.verticalHeader().hide()
 
# Set the default row height and hide the header
self.horizontalHeader().setDefaultSectionSize(THUMBNAIL_SIZE+SPACING)
self.horizontalHeader().hide()
 
# Set the table width to show all images without horizontal scrolling

self.setMinimumWidth((THUMBNAIL_SIZE+SPACING)*IMAGES_PER_ROW+(SPACING*2))
 
def addPicture(self, row, col, picturePath):
item=QTableWidgetItem()
 
# Scale the image by either height or width and then 'crop' it to the
# desired size, this prevents distortion of the image.
p=QPixmap(picturePath)
if p.height()>p.width(): p=p.scaledToWidth(THUMBNAIL_SIZE)
else: p=p.scaledToHeight(THUMBNAIL_SIZE)
p=p.copy(0,0,THUMBNAIL_SIZE,THUMBNAIL_SIZE)
item.setIcon(QIcon(p))
 
self.setItem(row,col,item)
 
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None, **kwargs):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
 
centralWidget=QWidget(self)
l=QVBoxLayout(centralWidget)
 
self.tableWidget=TableWidget(self)
l.addWidget(self.tableWidget)
 
self.setCentralWidget(centralWidget)
 

picturesPath=QDesktopServices.storageLocation(QDesktopServices.PicturesLocation)
pictureDir=QDir(picturesPath)
pictures=pictureDir.entryList(['*.jpg','*.png','*.gif'])
 
rowCount=len(pictures)//IMAGES_PER_ROW
if len(pictures)%IMAGES_PER_ROW: rowCount+=1
self.tableWidget.setRowCo

Python and mysql 3 tier programming

2013-08-21 Thread Gary Roach

Hi all,

I'm now to the list so apologies if I don't always follow the local 
protocol. My problem is the interface between python and mysql using a 
three tier model. First, some background:


System Debian Wheezy Linux
Python 2.7
Mysql 5.5.31
Apache Server

I am somewhat conversant with html, css, SQL, mysql, Apache and Debian 
Linux. Actually I have been using Debian for over 10 year. I spent over 
5 year, prior to retirement, programming database based applications in 
Foxpro. I can also struggle through Java Script. I am just starting to 
use python. I've started with development of a rather complicated 
document archiving system with about 5 different levels of users and 
over 100 years of documents. photos, etc. The database setup has gone 
smoothly and other than one trial web page I'm leaving that for later. 
Finally to the problem. Where does python start and mysql stored 
procedures stop and visa versa. I'm trying to stick to a 3 tier 
philosophy but am having trouble figuring out where the dividing line is 
between the two packages. Further python seems to like cursor tables a 
lot and Oracles Mysql 5.5 discourages their use. Are they talking about 
the same thing.


My problem is mostly with the basic architecture of the system. I think 
I will be able to figure out the code. Also, any comments on the use of 
the Django framework for this project.


Thanks in advance

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


Re: Encoding problem in python

2013-08-21 Thread electron
If you use Arabic frequently on your system, I suggest to change your
windows system locale from "Region and Language" in control panel
(Administrative tab) and set to Arabic.

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


RE: Unpickling data with classes from dynamic modules

2013-08-21 Thread Fredrik Tolf

On Wed, 21 Aug 2013, Prasad, Ramit wrote:

Fredrik Tolf wrote:

[...]
I considered trying to create subclasses of the pickler and unpickler that
pickle a reference to a module loader and data for the particular module
along with a class that comes from such a module, by overriding
Pickler.save_global and Unpickler.load_global. Unfortunately, however,
those functions aren't part of the public interface and can't be
overridden when the C-pickle module is used instead (which, obviously, is
what normally happens).
[...]


I believe rather than subclassing the pickler, you are expected to
change the behavior from within the class via __getstate__ and __setstate__.


Well, that clearly wouldn't work, since that still assumes the module can 
be found.



Maybe all you need to add is implementation for obj.__reduce__


That would certainly work, and I guess I could perhaps use it as a 
work-around, but that would mean I'd have to mark every single such class 
as such in some way or another. What I'm looking for is a solution that 
could make them picklable transparently, just like normal.


--

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


Re: PEPs should be included with the documentation download

2013-08-21 Thread Cameron Simpson
On 22Aug2013 03:32, Chris Angelico  wrote:
| Also, how many people actually depend on the downloadable
| documentation, rather than simply reading things online?

I do. It is outstandingly faster, and works when one is offline;
I always have a local copy of a 2.x and 3.x documentation set
as desktop icons, ready for instant opening.

I agree I rarely need the PEPs unless I want to look up something unusual.

Cheers,
-- 
Cameron Simpson 

I need your clothes, your boots, and your motorcycle.
- Arnold Schwarzenegger, Terminator 2
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I wonder if I would be able to collect data from such page using Python

2013-08-21 Thread Piet van Oostrum
Comment Holder  writes:

> Hi,
> I am totally new to Python. I noticed that there are many videos showing how 
> to collect data from Python, but I am not sure if I would be able to 
> accomplish my goal using Python so I can start learning.
>
> Here is the example of the target page:
> http://and.medianewsonline.com/hello.html
> In this example, there are 10 articles.
>
> What I exactly need is to do the following:
> 1- Collect the article title, date, source, and contents.
> 2- I need to be able to export the final results to excel or a database 
> client. That is, I need to have all of those specified in step 1 in one row, 
> while each of them saved in separate column. For example:
>
> Title1Date1   Source1   Contents1
> Title2Date2   Source2   Contents2
>
> I appreciate any advise regarding my case. 
>
> Thanks & Regards//

Here is an attempt for you. It uses BeatifulSoup 4. It is written in Python 
3.3, so if you want to use Python 2.x you will have to make some small changes, 
like
from urllib import urlopen
and probably something with the print statements.

The formatting in columns is left as an exercise for you. I wonder how you 
would want that with multiparagraph contents.

from bs4 import BeautifulSoup
from urllib.request import urlopen

URL = "http://and.medianewsonline.com/hello.html";
html = urlopen(URL).read()
soup = BeautifulSoup(html)
arts = soup.find_all('div', class_='articleHeader')

for art in arts:
name = art.contents[0].string.strip()
print(name)
artbody = art.find_next_sibling('div', class_='article enArticle')
titlenode = artbody.find_next('div', id='hd')
title = titlenode.get_text().strip()
print("Title: {0}".format(title))
srcnode = titlenode.find_next('a')
while srcnode.parent.get('class') == ['author']:
srcnode=srcnode.find_next('a')
source = srcnode.string
srcnode = srcnode.parent
date = srcnode.find_previous_sibling('div').string
print("Date: {0}".format(date))
print("Source: {0}".format(source))
cont = srcnode.find_next_siblings('p', class_='articleParagraph 
enarticleParagraph')
contents = '\n'.join([c.get_text() for c in cont])
print("Contents: {0}".format(contents))



-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
http://mail.python.org/mailman/listinfo/python-list


pydoc vs. non-def'd methods

2013-08-21 Thread Dan Sommers
Greetings,

I'm hava a class in which there are two equally useful names for one
method.  Consider this design (there are other approaches, but that's
not what my question is about):

class Spam1:

def eggs(self):
'''Return the Meaning of Life.'''
return 42

ham = eggs

help(Spam1) shows that ham = eggs(self), which isn't all bad, but it
could be better.  help(Spam1.ham) shows the help for eggs; I know why,
but this could be better as well.  And in any case, eggs looks somehow
better than ham, because eggs has its own def statement and ham doesn't.

Now consider this design, designed to overcome the previous issues:

class Spam2:

def _private(self):
'''Return the Meaning of Life.'''
return 42

ham = _private
eggs = _private

Now help(Spam2.ham) and help(Spam2.eggs) show the same thing, but
help(Spam2) hides _private and its docstring and shows that ham and eggs
both call _private.  That's no good.  I can expose _private (e.g., by
renaming it to public), but that defeats the purpose of making it
private in the first place.  I can go ahead and define ham to invoke
eggs, but then I have to duplicate the docstring, and it's not
being-hit-on-the-head obvious that ham and eggs are simply synonyms for
the same functionality.

I could put the documentation at the class level, but then it doesn't
show up as part of help(Spam2.eggs) or help(Spam1.ham).

So is there a clean way to define SpamN such that help(SpamN),
help(SpamN.ham), and help(SpamN.eggs) all do the Right Thing, and the
symmetry of ham and eggs is perfectly obvious to the most casual
observer?

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


Re: Basic Python Query

2013-08-21 Thread Bob Martin
in 704175 20130822 010625 Ned Batchelder  wrote:
>This is a multi-part message in MIME format.

Please post in plain text, not HTML.
-- 
http://mail.python.org/mailman/listinfo/python-list


Running a command line program and reading the result as it runs

2013-08-21 Thread Ian Simcock

Greetings all.

I'm using Python 2.7 under Windows and am trying to run a command line 
program and process the programs output as it is running. A number of 
web searches have indicated that the following code would work.


import subprocess

p = subprocess.Popen("D:\Python\Python27\Scripts\pip.exe list -o",
 stdout=subprocess.PIPE,
 stderr=subprocess.STDOUT,
 bufsize=1,
 universal_newlines=True,
 shell=False)
for line in p.stdout:
print line

When I use this code I can see that the Popen works, any code between 
the Popen and the for will run straight away, but as soon as it gets to 
the for and tries to read p.stdout the code blocks until the command 
line program completes, then all of the lines are returned.


Does anyone know how to get the results of the program without it blocking?

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


Re: How to keep cookies when making http requests (Python 2.7)

2013-08-21 Thread dieter
Luca Cerone  writes:

>...
> Have you tried this code to check if this work?

Not this code, but code like this (as I have written).

> If it works as intended can you explain a bit better
> what it does exactly?

Fabio already did the explanation.


Let me make an additional remark however: you should
not expect to get complete details in a list like this - but only
hints towards a solution for your problem (i.e.
there remains some work for you).
Thus, I expect you to read the "cookielib/cookiejar" documentation
(part of Python's standard documentation) in order to understand
my example code - before I would be ready to provide further details.

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


Re: Running a command line program and reading the result as it runs

2013-08-21 Thread Chris Angelico
On Thu, Aug 22, 2013 at 3:51 PM, Ian Simcock
 wrote:
> When I use this code I can see that the Popen works, any code between the
> Popen and the for will run straight away, but as soon as it gets to the for
> and tries to read p.stdout the code blocks until the command line program
> completes, then all of the lines are returned.
>
> Does anyone know how to get the results of the program without it blocking?

Is the program actually producing output progressively? I just tried
your exact code with "dir /ad /s /b" and it worked fine, producing
output while the dir was still spinning (obviously setting shell=True
to make that work, but I don't think that'll make a difference). It
may be that pip buffers its output. Is there a parameter to pip to
make it pipe-compatible?

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


Re: Unpickling data with classes from dynamic modules

2013-08-21 Thread dieter
Fredrik Tolf  writes:

> ...
>> Maybe all you need to add is implementation for obj.__reduce__
>
> That would certainly work, and I guess I could perhaps use it as a
> work-around, but that would mean I'd have to mark every single such
> class as such in some way or another. What I'm looking for is a
> solution that could make them picklable transparently, just like
> normal.

This is not (easily) possible. In the "normal/transparent" case,
"pickle" treats the class/type part of a class/type instance
(unless it explicitely knows the "class/type" as requiring special
treatment) as a "global" (essentially a module path and a name)
and it expects that "global"s can simply be imported.


The ZODB ("Zope Object DataBase") is build on top of "pickle"
("cpickle", in fact) - and it provides for an application level
module loader. Zope is using this feature to implement
so called "ZClasses", classes the code of which are maintained
inside the ZODB.

Thus, this is a case similar to yours
(your dynamic modules correspond to code maintained in the ZODB).
This implies that there are ways to achieve something like this
(in principle) and you may look how it is done in Zope to
get some ideas. However, it is likely to be difficult.
Your "module loader" must be able to recreate your dynamic
modules - for this, it needs all the creation input data.
In the Zope case, this comes from the ZODB. You would need
to find a way to pass this information to the unpickling process...

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


Re: pydoc vs. non-def'd methods

2013-08-21 Thread Steven D'Aprano
On Thu, 22 Aug 2013 05:13:03 +, Dan Sommers wrote:

> Greetings,
> 
> I'm hava a class in which there are two equally useful names for one
> method.  Consider this design (there are other approaches, but that's
> not what my question is about):

Generally though, one name will be the canonical or preferred name, and 
the other merely an alias. That being the case, it's reasonable for the 
alias to be "second class" in some fashion, as you show below.

 
> class Spam1:
> 
> def eggs(self):
> '''Return the Meaning of Life.'''
> return 42
> 
> ham = eggs
> 
> help(Spam1) shows that ham = eggs(self), which isn't all bad, but it
> could be better.  help(Spam1.ham) shows the help for eggs; I know why,
> but this could be better as well.

I'm not entirely sure how it could possibly be better. Since ham is just 
another name for eggs, it makes sense that they show the same docstring.


> And in any case, eggs looks somehow
> better than ham, because eggs has its own def statement and ham doesn't.

I don't think I agree, but perhaps that's just an aesthetic judgement 
where we disagree.

[...]
> So is there a clean way to define SpamN such that help(SpamN),
> help(SpamN.ham), and help(SpamN.eggs) all do the Right Thing, and the
> symmetry of ham and eggs is perfectly obvious to the most casual
> observer?

class Spam:
def eggs(self):
"""eggs docstring"""
return "ham and eggs"
def ham(self):
return self.eggs()
ham.__doc__ = eggs.__doc__.replace('eggs', 'ham')

This allows you two distinct docstrings, at the cost of duplicating the 
information in them. Spam.ham will be a *tiny* bit less efficient, due to 
the extra method call, but if you're worried about that, you're probably 
up to no good :-)

But really, I would find that a confusing API. I would wonder what subtle 
difference in semantics there was between ham and eggs. I would much 
prefer to see that ham was just an alias:

class Spam:
def eggs(self):
"""eggs docstring"""
pass
ham = eggs


which brings us back to the beginning of your post :-)

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


Re: A data transformation framework. A presentation inviting commentary.

2013-08-21 Thread dieter
"F.R."  writes:

> ...
> In an effort to do some serious cleaning up of a hopelessly cluttered
> working environment, I developed a modular data transformation system
> that pretty much stands. I am very pleased with it. I expect huge time
> savings. I would share it, if had a sense that there is an interest
> out there and would appreciate comments. Here's a description. I named
> the module TX:
>
> The nucleus of the TX system is a Transformer class, a wrapper for any
> kind of transformation functionality. The Transformer takes input as
> calling argument and returns it transformed. This design allows the
> assembly of transformation chains, either nesting calls or better,
> using the class Chain, derived from 'Transformer' and 'list'. A Chain
> consists of a sequence of Transformers and is functionally equivalent
> to an individual Transformer. A high degree of modularity results:
> ...

This high level description much resembles "Products.PortalTransforms",
a transformation package used in a "Plone" context.
This package is targeted towards "MIME type" based transformations,
i.e. input objects have a "MIME type" and you specify the target
"MIME type". A transform registry knows about the available
(elementary) transformations and determines a chain of transformations
to achieve a desired one.


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