Re: ElementTree Issue - Search and remove elements

2012-10-16 Thread Alain Ketterlin
Tharanga Abeyseela  writes:

> I need to remove the parent node, if a particular match found.

It looks like you can't get the parent of an Element with elementtree (I
would love to be proven wrong on this).

The solution is to find all nodes that have a Rating (grand-) child, and
then test explicitly for the value you're looking for.

> 
> http://schemas..xx/xx/2011/06/13/xx";>
> 
[...]
> 
> 
> M


> for child in 
> root.findall(".//{http://schemas.CCC.com/CCC/2011/06/13/CC}Rating";):
>x = child.find('Rating').text
> if child[1].text == 'NC':
> print "found"
>root.remove('TVEpisode') ?

Your code doesn't work because findall() already returns Rating
elements, and these have no Rating child (so your first call to find()
fails, i.e., returns None). And list indexes starts at 0, btw.

Also, Rating is not a child of TVEpisode, it is a child of
ParentalControl.

Here is my suggestion:

# Find nodes having a ParentalControl child
for child in root.findall(".//*[ParentalControl]"):
x = child.find("ParentalControl/Rating").text
if x == "NC":
...

Note that a complete XPath implementation would make that simpler: your
query basically is //*[ParentalControl/Rating=="NC"]

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


Re: OT Questions

2012-10-16 Thread Dwight Hutto
On Wed, Oct 17, 2012 at 2:06 AM, Demian Brecht  wrote:
>> This is my prototype portfolio for freelancing. If you have an honest
>> critique, then what, in your opinion, am I good at?
>>
>> https://www.odesk.com/users/~01710ac049863018eb
>
> I can't ascertain what your strengths are as I don't work with you on a daily 
> basis (one of the many benefits of working with people smarter than you ;)).

Doubt that, unless they have 160+ I.Q.'s(been seeing psychiatrists
since I was 13). I'm very secure in my childlike intellectualism.
>
> What I feel safe in assuming is that:
>
> * You seemingly have a *want* to learn, which in itself is very important.

Want to. I'm the most interdisciplinary learner you might have ever
encountered in your life. Like you said, you don't know me that well,
and this isn't intended to get mean...I just had to get honest with
myself without that much ego.

> * Your strength is not design. Using bevel and emboss (and a pattern here and 
> there) does not constitute good design.

It's simplicity within a symbolism, and now that I need money for
medical reasons, the work I've done isn't perfect, but it's on par.

I know when I see something aesthetically pleasing, and if I like what
I have, I'm using the same mindset.

If you're showcasing logo work, I hope you're ready to supply
variations that can be used cross-medium.

These are all portfolio sites of my own, and I'm slowly revising them,
just like any other rough draft, and as you can tell I'm asking other
people to critique it.

> * You're not a game developer

Not yet, but wait until you see a translated prototype from
python/tkinter turned into blender. I'm fond of games, and I try to
not mimic, but keep in the same realm of professional.

Remember you're looking at rough drafts, and you haven't seen other
developments.

 (given what I've seen, I highly doubt that you can readily tackle the
complexities in game development even in a team environment, let alone
solo)

You mean a GDK with a story line, points, and scores with little cool
graphics. Lowly doubt your opinion of that.

>
> Don't lie (this includes stretching the truth).

In which case have i lied. I'm capable of many things, and that's
confidence, not arrogance.

In doing so, you'll mismanage client expectations and simply drive any
future prospective clients away. Under-promise, over-deliver ;)
>
This I believe in somewhat, but I want to tell the client I can do it,
and they're the final inspector who oversees the project. I just
algorithm, develop, and deliver their expectations.


> As to not flood the list with OT discussion, if you can stay away from the 
> flame wars (I avoid such things, directly or indirectly as it's childish and 
> entirely unprofessional),

Defending yourself when attacked is a necessity. In business people
will run over you, steal your ideas, and take advantage of you, and I
can't let that happen in any forum, no matter how childish it can get.

I don't mind answering questions here and there (just e-mail me
directly). I'm not a genius or a guru, but I've had enough experience
that I may be of some help in pointing you in the right directions if
you're genuinely interested.

I'm a lonely guy, and I like friends. I only flame up in hostile
situations. So we can discuss this off list, and I'll accept any
advice I acknowledge as being beneficial, and will argu a point I
think is valid.


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


Re: Aggressive language on python-list

2012-10-16 Thread Steven D'Aprano
On Tue, 16 Oct 2012 21:25:38 -0700, alex23 wrote:

> I really don't get people who feel they need to share their opinion when
> that opinion is that other people shouldn't share theirs.

+1 QOTW

It makes me laugh when newcomers to this group stick their head up to 
chastise us for arguing about the culture of this group. The irony is 
that that is *precisely* what they too are doing.

In an ideal world, we'd all agree on what counts as acceptable behaviour, 
and stick to it, and discuss nothing but Python coding problems. But we 
don't live in an idea world, and there are disagreements and people 
behaving badly, and arguments about such, and meta-arguments about the 
arguments.

Welcome to humanity.

And more importantly, welcome to democracy -- this is not a dictatorship, 
there is no Supreme Glorious Leader who decides what is on- and off-
topic, no Thought Police to ban you for straying from the straight and 
narrow of what is allowed. And thank goodness for that. I've been on 
lists that do have such policies, and they tend to give lousy advice 
badly and have a culture of group-think.

Sure, it's frustrating to have to hit delete on a bunch of posts you 
don't care about. But that's true regardless of the topic or the list. 
Last night I deleted about 300 emails about designing a new asynchronous 
library that I had no desire to take part in. Did I post an angry screed 
calling it BS? No I did not, because I'm aware that even if I'm not 
interested in it, it is a part of Python culture and *somebody* needs to 
deal with it. I'm just glad its not me.



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


Re: OT Questions

2012-10-16 Thread Demian Brecht
> This is my prototype portfolio for freelancing. If you have an honest
> critique, then what, in your opinion, am I good at?
> 
> https://www.odesk.com/users/~01710ac049863018eb

I can't ascertain what your strengths are as I don't work with you on a daily 
basis (one of the many benefits of working with people smarter than you ;)).

What I feel safe in assuming is that:

* You seemingly have a *want* to learn, which in itself is very important.
* Your strength is not design. Using bevel and emboss (and a pattern here and 
there) does not constitute good design. If you're showcasing logo work, I hope 
you're ready to supply variations that can be used cross-medium.
* You're not a game developer (given what I've seen, I highly doubt that you 
can readily tackle the complexities in game development even in a team 
environment, let alone solo)

Don't lie (this includes stretching the truth). In doing so, you'll mismanage 
client expectations and simply drive any future prospective clients away. 
Under-promise, over-deliver ;)

As to not flood the list with OT discussion, if you can stay away from the 
flame wars (I avoid such things, directly or indirectly as it's childish and 
entirely unprofessional), I don't mind answering questions here and there (just 
e-mail me directly). I'm not a genius or a guru, but I've had enough experience 
that I may be of some help in pointing you in the right directions if you're 
genuinely interested.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ElementTree Issue - Search and remove elements

2012-10-16 Thread Stefan Behnel
Hi,

note that it's best to reply to responses you get, rather than starting a
new thread on the same topic. It helps in building up context and in
keeping details together at one point in the archive for users who run into
similar problems later.

Tharanga Abeyseela, 17.10.2012 07:47:
> I need to remove the parent node, if a particular match found.
> 
> ex:
> 
> 
> http://schemas..xx/xx/2011/06/13/xx";>
> 
> 0x5
> http://fxxl
> WWE
> WWE 
> WWE
> false
> 
> 
> BoxArt
> https://xx.xx/@006548-thumb.jpg
> 
> 
> 2012-10-16T00:00:19.814+11:00
> 
> x
> 
> 
> 
> M
> 
> 
> if i found NC, i need to remove the  from
> the XML. i have TVseries,Movies,and several items. (they also have
> Rating element). i need to remove all if i found the NC keyword.inside
> 
> 
> 
> im using following code.
> 
> when i do the following on python shell  i can see the result (NC,M,etc)
> 
> >>> x[1].text
> 'NC'
> 
> but when i do this inside the script, im getting the following error.
> 
> Traceback (most recent call last):
>   File "./test.py", line 10, in ?
> x = child.find('Rating').text
> AttributeError: 'NoneType' object has no attribute 'text'
> 
> 
> but how should i remove the parent node if i found the string "NC" i
> need to do this for all elements (TVEpisode,Movies,TVshow etc)
> how can i use python to remove the parent node if that string found.
> (not only TVEpisodes, but others as well)
> 
> 
> #!/usr/bin/env python
> 
> import elementtree.ElementTree as ET
> 
> tree = ET.parse('test.xml')
> root = tree.getroot()
> 
> 
> for child in 
> root.findall(".//{http://schemas.CCC.com/CCC/2011/06/13/CC}Rating";):
>x = child.find('Rating').text
> if child[1].text == 'NC':
> print "found"
>root.remove('TVEpisode') ?
> tree.write('output.xml')

The trick is to search for the parent node, then let your code find out if
you need to remove it or not by traversing its subtree.

Stefan


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


Re: OT Questions

2012-10-16 Thread Dwight Hutto
On Wed, Oct 17, 2012 at 1:25 AM, Demian Brecht  wrote:
>>
>> You haven't been on lists long enough then to have seen some real
>> flame warts...no offense.
>
> No offense taken, it's why I said it in the first place ;) Having said that, 
> generally engaging in flame wars solves nothing and sheds a negative light on 
> the individuals who take part in it.
>
>> It's in a design phase, and I'm asking the local experts to critique
>> it, and even be harsh.
>
> You're not a designer. There's nothing at all wrong with that (I'm not either 
> for the record). Most aren't good at both left *and* right-brained functions. 
> My sincere suggestion is pick which aspect of development piques your 
> interest the most and follow that. Delegate the other aspects to others who 
> are good at what they do.
>
> Remember.. You're asking for feedback here :)
>
>> It was meant as more of a commercial to show a little more umph in my
>> site presentation, and I'm working on reducing the size through
>> several different means.
>
> It's a bad way of advertising your business. In this day and age, there will 
> likely be less people looking for potential contractors on desktop systems 
> than on mobile devices. As such, you want to make sure that your site has 
> very little in the way of heavy graphics (unless there's a version that the 
> user gets redirected to that's mobile-friendly). Take advantage of 
> client-side rendering where possible.
>
>> I know this, and I'm trying to reduce it, but show something that's 
>> appealing.
>
> My point was that it shouldn't be there *at all*. Automatically playing music 
> is widely thought of as being annoying and does absolutely nothing at all for 
> your business. You're not selling games, you're not selling DJ services. I 
> can guarantee that you will turn away more prospective business by having the 
> music there in the first place than not having any at all.
>
>> I kind of like my designs, and they're being refined through these
>> conversations.
>
> I like my designs too. However, I realized *long* ago that I'm not good at 
> them. I even grew to dislike even doing design work because of how much extra 
> time and effort it took to develop something decent rather than just 
> concentrating on what I was good at. My designs wouldn't hold up compared to 
> other professional entities and unless there are remarkable improvements, 
> yours won't either.
>
>> I like w3schools.com, and I know that it's a rough draft, and so
>> should my critics.
>
> w3schools is generally thought of as being a bad resource. Take a read 
> through http://w3fools.com (there are many other resources, that was just the 
> first one that popped up on Google search). Udacity has a high powered 
> academic faculty. Coursera is another great resource. Both have content that 
> you'll never get from resources like w3schools. Open higher learning is where 
> it's at.
>
>> I like to work alone, and his is an attempt to get others in the OS
>> community to comment.
>
> Working alone is almost always the worst thing that you can do if you're new 
> (or newer) to development, design, user experience or any combination 
> thereof. Surrounding yourself with people smarter than you is the best way to 
> learn and grow. Sure, you can attempt to get some of that over mailing lists 
> and the like, but nothing will *ever* beat in-person environments.
>

This is my prototype portfolio for freelancing. If you have an honest
critique, then what, in your opinion, am I good at?

https://www.odesk.com/users/~01710ac049863018eb


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


Re: Tkinter how to access the widget by name

2012-10-16 Thread Владимир Пылев
вторник, 16 октября 2012 г., 2:26:22 UTC+4 пользователь Prasad, Ramit написал:
>  ? wrote:
> 
> > I'm a little teapot ... himself the question: if I want to appeal to the 
> > widget, knowing his name... ?
> 
> > 
> 
> > # appropriated the name of the widget
> 
> > label = Label(frame, width = 40, text='text', name = 'name')
> 
> > ...
> 
> > name_='name'
> 
> > configure(name_)
> 
> > ...
> 
> > def configure(name_)
> 
> > #And how can that be?
> 
> > # At least let the text you want to change 
> 
> > 
> 
> > I beg you ..
> 
> > --
> 
> 
> 
> I am unfamiliar with Tkinter, so this might not be very helpful.
> 
> 
> 
> Usually with the GUI I have created before I uses classes and store 
> 
> the widgets inside the classes. That makes it easier to use
> 
> `self.widgetname` or `getattr(self, widgetname)`. If that is not
> 
> something you can instead store the attributes in a list/dictionary.
> 
> In both cases make sure not to have multiple widgets created with
> 
> the same name.
> 
> 
> 
> Note the following is all untested and should be considered pseudo-code.
> 
> 
> 
> widgets = {}
> 
> label = Label(frame, width = 40, text='text', name = 'name')
> 
> widgets['name'] = label
> 
> 
> 
> def configure(name_):
> 
> widget = widgets[name_] 
> 
> 
> 
> OR
> 
> 
> 
> widgets = []
> 
> label = Label(frame, width = 40, text='text', name = 'name')
> 
> widgets.append( label )
> 
> 
> 
> def configure(name_):
> 
> found = False
> 
> for w in widgets:
> 
>  if w.name == name_: # No idea how to get name from Tk widget
> 
>found = True
> 
>break
> 
>  if found:
> 
> # configure here
> 
> 
> 
> 
> 
> Ramit Prasad
> 
> 
> 
> 
> 
> This email is confidential and subject to important disclaimers and
> 
> conditions including on offers for the purchase or sale of
> 
> securities, accuracy and completeness of information, viruses,
> 
> confidentiality, legal privilege, and legal entity disclaimers,
> 
> available at http://www.jpmorgan.com/pages/disclosures/email.


ok thanks, that this method is suitable in full: "widgets.append( label )" , 
аlthough at the beginning wanted to access the widget by its internal name, but 
I left this venture )).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list comprehension question

2012-10-16 Thread Terry Reedy

On 10/16/2012 9:54 PM, Kevin Anthony wrote:

I've been teaching myself list comprehension, and i've run across
something i'm not able to convert.


list comprehensions specifically abbreviate the code that they are 
(essentially) equivalent to.


res = []
for item in source:
  res.append(f(item))
res

<==>

[f(item) for item in source]

Matrix multiplication does not fit the pattern above. The reduction is 
number addition rather than list appending.


--
Terry Jan Reedy

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


Re: Aggressive language on python-list

2012-10-16 Thread Terry Reedy

On 10/16/2012 11:47 PM, Kristen J. Webb wrote:


I will say that my perusal of this list has been
informative.  I also receive more email from this
list than any other I subscribe to.


You could instead access it as a newsgroup via news.gmane.org. That 
keeps posts isolated and you only download those item you request. News 
readers should collapse threads to a single line and allow you to mark 
all as read.


--
Terry Jan Reedy

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


Re: list comprehension question

2012-10-16 Thread Dwight Hutto
On Wed, Oct 17, 2012 at 12:43 AM, Kevin Anthony
 wrote:
> Is it not true that list comprehension is much faster the the for loops?
>
> If it is not the correct way of doing this, i appoligize.
> Like i said, I'm learing list comprehension.
>
I thought it was matrix multiplication mixed with list comprehension.

Check this out real quick from the docs for list comprehension, but if
it's a mixture of matrix multi, and list comp, then reply back.

http://docs.python.org/tutorial/datastructures.html#list-comprehensions


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


Re: Aggressive language on python-list

2012-10-16 Thread rusi
On Oct 17, 9:25 am, alex23  wrote:
> On Oct 17, 1:54 pm, "Kristen J. Webb"  wrote:
>
> > It sucks for me to spend so much time filtering this BS.
>
> Yet you then chose to participate in a discussion about it. Because
> that's what people do to discuss suitable behaviour.
>
> I really don't get people who feel they need to share their opinion
> when that opinion is that other people shouldn't share theirs.

Ha Ha!
Let me try to restate alex without the barb.

What exactly do you (Kristen) find to be BS?

If its the one-line endorsement from David to Steven, Ive no comment
or opinion
If its the hundreds of lines of Steven's post, it would be good if
your mail-quoting singles that out.
If its Zero's OP then I am sorry, but many of us think that something
needs to be said.

In case its the length of Steven's post here's my attempt at improving
his S/N ration:
There are dicks and there are trolls. Behavior can be improved by
calling right things by the right names.

[My addition]:
1. There are no dicks and trolls; there is dick-ing and trolling
2. jmf's objections to python's unicode is classic trolling. David's
abusive language is dicking.
Using the right name helps to find the right strategy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list comprehension question

2012-10-16 Thread Kevin Anthony
Is it not true that list comprehension is much faster the the for loops?

If it is not the correct way of doing this, i appoligize.
Like i said, I'm learing list comprehension.

Thanks
Kevin
On Oct 16, 2012 10:14 PM, "Dave Angel"  wrote:

> On 10/16/2012 09:54 PM, Kevin Anthony wrote:
> > I've been teaching myself list comprehension, and i've run across
> something
> > i'm not able to convert.
> >
> > here's the original code for matrix multiplcation
> >
> > retmatrix = Matrix(self.__row,other.__col)
> > for m in range(0,retmatrix.__row):
> > for n in range(0,retmatrix.__col):
> > product = 0
> > for p in range(1,self.__col+1):
> > product += (self.__matrix[m][p] * other.__matrix[p][n])
> > retmatrix.__matrix[m][n] = product
> >
> > Here is what i have so far:
> > retmatrix.__matrix = [[ product = product + (self.__matrix[m][p]*
> > other.__matrix[p][n])
> >  if product else self.__matrix[m][p]*
> other.__matrix[p][n])
> >  for p in range(0,self.col)
> >  for n in range(0,self.col)]
> >  for m in range(0,self.__row)]
> >
> > But i know that isn't correct, can someone nudge my in the right
> direction?
> >
> >
>
> The biggest thing to learn about list comprehensions is when not to use
> them.  I can't imagine how your latter version (even if correct) is
> clearer than the first.
>
>
>
> --
>
> DaveA
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Aggressive language on python-list

2012-10-16 Thread Ben Finney
"Kristen J. Webb"  writes:

> What the f**k! I thought that subscribing to a list would promote
> education, enlightenment, and a shared communal effort to make things
> better for things (python) related.

Yes, that's the focus of this thread: how best to engage in a shared
communal effort to make things better for Python-related discussion.

> It sucks for me to spend so much time filtering this BS.

The thread helpfully tells you what it's about in the subject field, and
remains remarkably on-topic by that description. Filter appropriately.

If it sucks for you to receive a high-volume discussion forum in your
email, you may want to use a better email client with more sophisticated
filtering capability. Or you can subscribe to the forum as a Usenet
newsgroup, news:comp.lang.python>.

> Let's be honest, does any of this crap have anything to do with
> python, it's promotion,

Yes, I think this discussion does have direct relevance to supporting
the promotion of Python. My views on how have been made elsewhere in
this same thread.

-- 
 \ “Teach a man to make fire, and he will be warm for a day. Set a |
  `\   man on fire, and he will be warm for the rest of his life.” |
_o__) —John A. Hrastar |
Ben Finney

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


Re: Aggressive language on python-list

2012-10-16 Thread alex23
On Oct 17, 1:54 pm, "Kristen J. Webb"  wrote:
> Let's be honest, does any of this crap have
> anything to do with python, it's promotion,
> or resolving anything related to making it
> one of the most exciting languages I have
> ever seen since C?

Python is more than the language, it's the community as well.
Discussing acceptable behaviour on a community mailing list is highly
relevant. Wanting to stop behaviour that could potentially drive
people away from the language is very much about promotion.

> It sucks for me to spend so much time filtering this BS.

Yet you then chose to participate in a discussion about it. Because
that's what people do to discuss suitable behaviour.

I really don't get people who feel they need to share their opinion
when that opinion is that other people shouldn't share theirs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: overriding equals operation

2012-10-16 Thread 88888 Dihedral
Pradipto Banerjee於 2012年10月16日星期二UTC+8下午9時59分05秒寫道:
> I am trying to define class, where if I use a statement a = b, then instead 
> of "a" pointing to the same instance as "b", it should point to a copy of 
> "b", but I can't get it right.
> 
> 
> 
> Currently, I have the following:
> 
> 
> 
> 
> 
> 
> 
> class myclass(object):
> 
> def __init__(self, name='')
> 
> self.name = name
> 
> 
> 
> def copy(self):
> 
> newvar = myclass(self.name)
> 
> return newvar
> 
> 
> 
> def __eq__(self, other):
> 
> if instance(other, myclass):
> 
> return self == other.copy()
> 
> return NotImplemented
> 
> 
> 
> 
> 
> Now if I try:
> 
> 
> 
> >>> a=myclass()
> 
> >>> a.name = 'test'
> 
> >>> b=a
> 
What you really want is b=a.copy() 
not b=a to disentangle two objects.

__eq__ is used in the comparison operation. 
 


> >>> b.name
> 
> 'test'
> 
> >>> b.name = 'test2'
> 
> >>> a.name
> 
> 'test2'
> 
> 
> 
> I wanted b=a to make a new copy of "a", but then when I assigned b.name = 
> 'test2', even a.name became 'test2'.
> 
> 
> 
> How can I rectify my code to make the __eq__() behave like copy()?
> 
> 
> 
> Thanks
> 
> 
> 
> 
> 
>  This communication is for informational purposes only. It is not intended to 
> be, nor should it be construed or used as, financial, legal, tax or 
> investment advice or an offer to sell, or a solicitation of any offer to buy, 
> an interest in any fund advised by Ada Investment Management LP, the 
> Investment advisor.  Any offer or solicitation of an investment in any of the 
> Funds may be made only by delivery of such Funds confidential offering 
> materials to authorized prospective investors.  An investment in any of the 
> Funds is not suitable for all investors.  No representation is made that the 
> Funds will or are likely to achieve their objectives, or that any investor 
> will or is likely to achieve results comparable to those shown, or will make 
> any profit at all or will be able to avoid incurring substantial losses.  
> Performance results are net of applicable fees, are unaudited and reflect 
> reinvestment of income and profits.  Past performance is no guarantee of 
> future results. All financial data and other information are not warranted as 
> to completeness or accuracy and are subject to change without notice.
> 
> 
> 
> Any comments or statements made herein do not necessarily reflect those of 
> Ada Investment Management LP and its affiliates. This transmission may 
> contain information that is confidential, legally privileged, and/or exempt 
> from disclosure under applicable law. If you are not the intended recipient, 
> you are hereby notified that any disclosure, copying, distribution, or use of 
> the information contained herein (including any reliance thereon) is strictly 
> prohibited. If you received this transmission in error, please immediately 
> contact the sender and destroy the material in its entirety, whether in 
> electronic or hard copy format.

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


Re: Aggressive language on python-list

2012-10-16 Thread Kristen J. Webb

As a casual observer of this list (and many others)

I can only say...

What the f**k!  I thought that subscribing to
a list would promote education, enlightenment,
and a shared communal effort to make things better
for things (python) related.

It sucks for me to spend so much time filtering this BS.

I will say that my perusal of this list has been
informative.  I also receive more email from this
list than any other I subscribe to.

Let's be honest, does any of this crap have
anything to do with python, it's promotion,
or resolving anything related to making it
one of the most exciting languages I have
ever seen since C?

Jeesh!
K



On 10/16/12 9:01 PM, Dwight Hutto wrote:

On Tue, Oct 16, 2012 at 10:45 PM, Steven D'Aprano
 wrote:

On Tue, 16 Oct 2012 14:10:17 -0700, rurpy wrote:


On 10/16/2012 10:49 AM, Steven D'Aprano wrote:

On Tue, 16 Oct 2012 09:27:48 -0700, rurpy wrote about trolls and
dicks:


No, I wrote about trolls.  "dicks" is a highly emotive and almost
totally subjective word


As opposed to "troll", which is unemotional and objective? Not.



that I would not use in a rational discussion.


I would. If someone is acting like a dick, why not call them by the word
that most accurately describes their behaviour?

I see nothing troll like in Dwight "call me David, but I can't be
bothered changing my signature" Hutto's behaviour. He doesn't seem to be
trolling, in either sense: he doesn't appear to be making provocative
statements for the purpose of making people think, nor does he seem to be
making inflammatory statements to get a rise out of people. He seems to
genuinely want to help people, in a clumsy, aggressive, and I believe
often intoxicated way.

So it seems to me that you are wrongly applying the term "troll" as a
meaningless pejorative to anyone who behaves badly.



Perhaps you were trying to be amusing?


Certainly not.



The best advise is to ignore such posts and encourage others to do
the same.

[...]

How should somebody distinguish between "I am being shunned for
acting like a dick", and "I have not received any responses because
nobody has anything to add"?


Because you sent them private email telling them that?


My, what a ... unique ... concept of "ignore such posts" you have.

So far, this has been the best advice you have given so far. My opinion
is that there is a graduated response to dickish behaviour:

* send a message telling the person they are acting unacceptably,
   preferably privately on a first offence to avoid public shaming
   (when possible -- lots of people aren't privately contactable
   for many reasons other than that they are trolls);

* if the behaviour continues, make a public comment condemning
   that behaviour generally without engaging directly in a debate
   or "tit-for-tat" argument with the person.


And for those who value their own peace and quiet over the community
benefit:

* block or killfile posts from that person so they don't
   have to be seen, preferably publicly.

When I killfile someone, I tend to make it expire after a month or three,
just in case they mend their ways. Call me Mr Softy if you like.


[...]

If I believe that your behaviour ("giving lousy advice") is causing
great harm to this community, and *I don't say anything*, how will
you know to change your behaviour?


If that was how you thought, then you would be someone I hope would
follow my advice.  Because you would clearly seem to be unable to
distinguish between difference of opinion on a subject relevant to the
newsgroup, and inflammatory trolling. Further you see the situation in
extreme terms ("*great harm*") and one in which only a single point of
view (your's) is acceptable.


As opposed to only your opinion being acceptable? Why on earth should I
follow your advice if I think it is bad advice?

We can't both be right[1]. We can't simultaneously confront bad
behaviour, and ignore bad behaviour. I think your advice is bad, and has
the potential to kill this community. You think my advice is bad, and has
the potential to kill this community. Except that you've made a 180-
degree turn from your advice to "ignore" bad behaviour, but apparently
didn't notice that *sending private emails* is not by any definition
"ignoring". So apparently you don't actually agree with your own advice.



You would be bordering on delusional by
thinking your post would somehow change my "behavior".


It's not necessarily about changing your behaviour. (Well, in this case,
it's less about you than about Dwight Hutto specifically and badly-
behaved posters in general.) It's about sending a message that the
behaviour is unacceptable.

The primary purpose of that message is to discourage *others* from
following in the same behaviour. Nothing will kill a forum faster than
trolls and dicks feeding off each other, until there is nothing left but
trolls and dicks. A single troll doesn't do much harm -- few of them have
the energy to spam a news group for long periods, drowning out useful

Re: list comprehension question

2012-10-16 Thread rusi
On Oct 17, 7:14 am, Dave Angel  wrote:
> On 10/16/2012 09:54 PM, Kevin Anthony wrote:
>
>
>
>
>
>
>
>
>
> > I've been teaching myself list comprehension, and i've run across something
> > i'm not able to convert.
>
> > here's the original code for matrix multiplcation
>
> > retmatrix = Matrix(self.__row,other.__col)
> > for m in range(0,retmatrix.__row):
> >     for n in range(0,retmatrix.__col):
> >         product = 0
> >         for p in range(1,self.__col+1):
> >             product += (self.__matrix[m][p] * other.__matrix[p][n])
> >         retmatrix.__matrix[m][n] = product
>
> > Here is what i have so far:
> > retmatrix.__matrix = [[ product = product + (self.__matrix[m][p]*
> > other.__matrix[p][n])
> >                  if product else self.__matrix[m][p]* other.__matrix[p][n])
> >                  for p in range(0,self.col)
> >                  for n in range(0,self.col)]
> >                  for m in range(0,self.__row)]
>
> > But i know that isn't correct, can someone nudge my in the right direction?
>
> The biggest thing to learn about list comprehensions is when not to use
> them.  I can't imagine how your latter version (even if correct) is
> clearer than the first.
>
> --
>
> DaveA

Try rewriting using dot

from operator import mul
def dot(p,q):
  return reduce(mul, [x*y for x,y in zip(p,q)])  # the [] can become
()

and avoiding object-orientation (at least to start with)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Aggressive language on python-list

2012-10-16 Thread rusi
On Oct 16, 9:27 pm, ru...@yahoo.com wrote:
> On 10/14/2012 10:36 PM, alex23 wrote:> On Oct 15, 1:22 pm, ru...@yahoo.com 
> wrote:
>
> >> Thus when a member of this esteemed group
> >> was recently attacked as racist, for punning another member's
> >> name when responding somewhat heatedly,
>
> > Again, there is a difference between "attacking" someone "as racist"
> > and *criticising* their *comments* as *possibly* racist. When the
> > person whose name was being punned said that they themselves were
> > unsure whether it was intended as a racial attack, then the behaviour
> > was worth commenting on.
>
> I just went back and reread what you and some others wrote
> to make sure I was not misremembering and am comfortable
> sticking with my description.  (FTR, your initial response
> was "Please, don't be a dick.")
>
> My intent was not to reargue that issue but to point out
> that different people have differing ideas on what is
> "acceptable" and "unacceptable" here and that if Ben
> Finney's advice to respond (in moderation) whenever one
> reads an "unacceptable" opinion is taken, one will create
> an environment in which troll's will flourish.
>
> The best advise is to ignore such posts and encourage
> others to do the same.

Trolling posts certainly exist. And when 'troll' becomes a short-form
for 'one-who-regularly-trolls' its fine as long as we remember that
its a metonymy.

When we forget
http://www.youtube.com/watch?v=FMEe7JqBgvg
should help by:
1. Showing how to deal with trolling
2. Reminding that such beings dont actually exist except as caricature

Coming to current misbehavior on the list -- specifically Etienne's
outburst against Steven,
I am reminded of a similar situation a year ago

Long thread -- Relevant starting is here
http://mail.python.org/pipermail/python-list/2011-May/604893.html

Abusive post
http://mail.python.org/pipermail/python-list/2011-May/604914.html

Maybe easier to read
http://groups.google.com/group/comp.lang.python/browse_thread/thread/17dca3bf467c9001/c53102a45da19386

The last thing that John Bokma posted (to the best of my knowledge)
was:

> Ben Finney  writes:
>
>>> Get a life. Or better, just fuck off and die. It will improve both the
>>> world and the Python community, of which you are nothing but a little,
>>> smelly shitstain.
>>
>> That abuse is entirely unwelcome in this community, against any person.
>> Please desist.

> You should have spoken up sooner, especially as the spokes person of
> "this" community. But every bully has is fan club.
>
> --
> John Bokma

If we think/feel that John Bokma was trolling then driving him off the
list was a good thing.
If not we need to question whether those actions were collectively
sound.

Specifically Steven's post that triggered Etienne's misbehavior is
this:

On Oct 5, 5:22 am, Steven D'Aprano  wrote:
> On Thu, 04 Oct 2012 14:10:46 -0400, Etienne Robillard wrote:
> > Dear list,
>
> > Due to lack of energy and resources i'm really sad to announce the
> > removal ofnotmmfrom pypi and bitbucket.
>
> Well that's just rude. Even if you don't intend to maintain the software
> any more, why are you removing it from pypi? Since you say you are a fan
> of Open Source software, just flag it as unmaintained and leave it for
> somebody else to pick up.
>
> If you are going to abandon the project, release it on PyPI with a dual
> MIT and GPL licence, and let it be taken over by somebody else.
>
> If you were looking for sympathy here, starting off by removing your
> project from free hosting, then complaining that you can't pay for the
> non-free hosting, was NOT the right way to do so.
:

> Steven

I read Etienne as saying: 'I need money (or at least some sympathy)'
Steven is unequivocally saying 'You are not getting it from here'

Technically he is correct; humanly I am not so sure.

[I have a personal regret that I did not rebut Steven's rudeness with
a '... that is not necessarily the view of the whole group...'
I hesitated to do so because I am not adept at giving sympathy without
giving false hope and keeping the post at reasonable length.
Anyhow this (too long) post is an attempt at correcting that.]

In the earlier (Quora-thread) Terry Reedy's voice was most balanced
and sane; unfortunately covered in the 'dog-pile' of all the rest.

Hopefully he will put in his word here as well.
[And Zero thank you for starting this thread]

Rusi

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


Re: Aggressive language on python-list

2012-10-16 Thread Dwight Hutto
On Tue, Oct 16, 2012 at 10:45 PM, Steven D'Aprano
 wrote:
> On Tue, 16 Oct 2012 14:10:17 -0700, rurpy wrote:
>
>> On 10/16/2012 10:49 AM, Steven D'Aprano wrote:
>>> > On Tue, 16 Oct 2012 09:27:48 -0700, rurpy wrote about trolls and
>>> > dicks:
>>
>> No, I wrote about trolls.  "dicks" is a highly emotive and almost
>> totally subjective word
>
> As opposed to "troll", which is unemotional and objective? Not.
>
>
>> that I would not use in a rational discussion.
>
> I would. If someone is acting like a dick, why not call them by the word
> that most accurately describes their behaviour?
>
> I see nothing troll like in Dwight "call me David, but I can't be
> bothered changing my signature" Hutto's behaviour. He doesn't seem to be
> trolling, in either sense: he doesn't appear to be making provocative
> statements for the purpose of making people think, nor does he seem to be
> making inflammatory statements to get a rise out of people. He seems to
> genuinely want to help people, in a clumsy, aggressive, and I believe
> often intoxicated way.
>
> So it seems to me that you are wrongly applying the term "troll" as a
> meaningless pejorative to anyone who behaves badly.
>
>
>> Perhaps you were trying to be amusing?
>
> Certainly not.
>
>
 >> The best advise is to ignore such posts and encourage others to do
 >> the same.
> [...]
>>> > How should somebody distinguish between "I am being shunned for
>>> > acting like a dick", and "I have not received any responses because
>>> > nobody has anything to add"?
>>
>> Because you sent them private email telling them that?
>
> My, what a ... unique ... concept of "ignore such posts" you have.
>
> So far, this has been the best advice you have given so far. My opinion
> is that there is a graduated response to dickish behaviour:
>
> * send a message telling the person they are acting unacceptably,
>   preferably privately on a first offence to avoid public shaming
>   (when possible -- lots of people aren't privately contactable
>   for many reasons other than that they are trolls);
>
> * if the behaviour continues, make a public comment condemning
>   that behaviour generally without engaging directly in a debate
>   or "tit-for-tat" argument with the person.
>
>
> And for those who value their own peace and quiet over the community
> benefit:
>
> * block or killfile posts from that person so they don't
>   have to be seen, preferably publicly.
>
> When I killfile someone, I tend to make it expire after a month or three,
> just in case they mend their ways. Call me Mr Softy if you like.
>
>
> [...]
>>> > If I believe that your behaviour ("giving lousy advice") is causing
>>> > great harm to this community, and *I don't say anything*, how will
>>> > you know to change your behaviour?
>>
>> If that was how you thought, then you would be someone I hope would
>> follow my advice.  Because you would clearly seem to be unable to
>> distinguish between difference of opinion on a subject relevant to the
>> newsgroup, and inflammatory trolling. Further you see the situation in
>> extreme terms ("*great harm*") and one in which only a single point of
>> view (your's) is acceptable.
>
> As opposed to only your opinion being acceptable? Why on earth should I
> follow your advice if I think it is bad advice?
>
> We can't both be right[1]. We can't simultaneously confront bad
> behaviour, and ignore bad behaviour. I think your advice is bad, and has
> the potential to kill this community. You think my advice is bad, and has
> the potential to kill this community. Except that you've made a 180-
> degree turn from your advice to "ignore" bad behaviour, but apparently
> didn't notice that *sending private emails* is not by any definition
> "ignoring". So apparently you don't actually agree with your own advice.
>
>
>> You would be bordering on delusional by
>> thinking your post would somehow change my "behavior".
>
> It's not necessarily about changing your behaviour. (Well, in this case,
> it's less about you than about Dwight Hutto specifically and badly-
> behaved posters in general.) It's about sending a message that the
> behaviour is unacceptable.
>
> The primary purpose of that message is to discourage *others* from
> following in the same behaviour. Nothing will kill a forum faster than
> trolls and dicks feeding off each other, until there is nothing left but
> trolls and dicks. A single troll doesn't do much harm -- few of them have
> the energy to spam a news group for long periods, drowning out useful
> posts.
>
>
>> But even if you had a more rational response
>
> *raises eyebrow*
>
>> and saved that reaction for
>> actual trolling and not someone who simply disagreed with you, I ask
>> again, what makes you think your response will change that troll's
>> behavior, when in actuality, your kind of response is exactly what most
>> trolls hope to elicit?  Did it help in the case I mentioned?
>
> As I said, I do not believe that Dwight Hutto is a troll. I believe he i

Re: Aggressive language on python-list

2012-10-16 Thread Steven D'Aprano
On Wed, 17 Oct 2012 02:45:04 +, Steven D'Aprano wrote:

> Dwight "call me David, but I can't be bothered changing my signature"
> Hutto's behaviour.

I withdraw this dig at David Hutto. It was unnecessary, and it turns out, 
wrong as he has now changed his signature.


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


Re: Aggressive language on python-list

2012-10-16 Thread Steven D'Aprano
On Tue, 16 Oct 2012 14:10:17 -0700, rurpy wrote:

> On 10/16/2012 10:49 AM, Steven D'Aprano wrote:
>> > On Tue, 16 Oct 2012 09:27:48 -0700, rurpy wrote about trolls and
>> > dicks:
> 
> No, I wrote about trolls.  "dicks" is a highly emotive and almost
> totally subjective word 

As opposed to "troll", which is unemotional and objective? Not.


> that I would not use in a rational discussion. 

I would. If someone is acting like a dick, why not call them by the word 
that most accurately describes their behaviour?

I see nothing troll like in Dwight "call me David, but I can't be 
bothered changing my signature" Hutto's behaviour. He doesn't seem to be 
trolling, in either sense: he doesn't appear to be making provocative 
statements for the purpose of making people think, nor does he seem to be 
making inflammatory statements to get a rise out of people. He seems to 
genuinely want to help people, in a clumsy, aggressive, and I believe 
often intoxicated way.

So it seems to me that you are wrongly applying the term "troll" as a 
meaningless pejorative to anyone who behaves badly.


> Perhaps you were trying to be amusing?

Certainly not.


>>> >> The best advise is to ignore such posts and encourage others to do
>>> >> the same.
[...]
>> > How should somebody distinguish between "I am being shunned for
>> > acting like a dick", and "I have not received any responses because
>> > nobody has anything to add"?
> 
> Because you sent them private email telling them that? 

My, what a ... unique ... concept of "ignore such posts" you have.

So far, this has been the best advice you have given so far. My opinion 
is that there is a graduated response to dickish behaviour:

* send a message telling the person they are acting unacceptably,
  preferably privately on a first offence to avoid public shaming
  (when possible -- lots of people aren't privately contactable 
  for many reasons other than that they are trolls);

* if the behaviour continues, make a public comment condemning 
  that behaviour generally without engaging directly in a debate
  or "tit-for-tat" argument with the person.


And for those who value their own peace and quiet over the community 
benefit:

* block or killfile posts from that person so they don't
  have to be seen, preferably publicly.

When I killfile someone, I tend to make it expire after a month or three, 
just in case they mend their ways. Call me Mr Softy if you like.


[...]
>> > If I believe that your behaviour ("giving lousy advice") is causing
>> > great harm to this community, and *I don't say anything*, how will
>> > you know to change your behaviour?
> 
> If that was how you thought, then you would be someone I hope would
> follow my advice.  Because you would clearly seem to be unable to
> distinguish between difference of opinion on a subject relevant to the
> newsgroup, and inflammatory trolling. Further you see the situation in
> extreme terms ("*great harm*") and one in which only a single point of
> view (your's) is acceptable.

As opposed to only your opinion being acceptable? Why on earth should I 
follow your advice if I think it is bad advice?

We can't both be right[1]. We can't simultaneously confront bad 
behaviour, and ignore bad behaviour. I think your advice is bad, and has 
the potential to kill this community. You think my advice is bad, and has 
the potential to kill this community. Except that you've made a 180-
degree turn from your advice to "ignore" bad behaviour, but apparently 
didn't notice that *sending private emails* is not by any definition 
"ignoring". So apparently you don't actually agree with your own advice.


> You would be bordering on delusional by
> thinking your post would somehow change my "behavior".

It's not necessarily about changing your behaviour. (Well, in this case, 
it's less about you than about Dwight Hutto specifically and badly-
behaved posters in general.) It's about sending a message that the 
behaviour is unacceptable.

The primary purpose of that message is to discourage *others* from 
following in the same behaviour. Nothing will kill a forum faster than 
trolls and dicks feeding off each other, until there is nothing left but 
trolls and dicks. A single troll doesn't do much harm -- few of them have 
the energy to spam a news group for long periods, drowning out useful 
posts.


> But even if you had a more rational response 

*raises eyebrow*

> and saved that reaction for
> actual trolling and not someone who simply disagreed with you, I ask
> again, what makes you think your response will change that troll's
> behavior, when in actuality, your kind of response is exactly what most
> trolls hope to elicit?  Did it help in the case I mentioned?

As I said, I do not believe that Dwight Hutto is a troll. I believe he is 
merely badly behaved. And yes, I do believe that confronting him has 
changed his behaviour, at least for now.

Not immediately, of course. His immediate response was to retaliate and 
defend hi

Re: OT Questions

2012-10-16 Thread Steven D'Aprano
On Tue, 16 Oct 2012 21:06:24 -0400, David Hutto wrote:

> I'm working on toning down the smack talk, I'm just used to a little
> witty back and forth with some seriously cruel individuals.

Thank you David, that is appreciated.

I see that you have changed your signature to match your preferred name 
(David rather than Dwight). You might not realise that your "From 
address" still says Dwight -- I had to manually change it above.



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


Re: list comprehension question

2012-10-16 Thread Dwight Hutto
On Tue, Oct 16, 2012 at 10:13 PM, Dave Angel  wrote:
> On 10/16/2012 09:54 PM, Kevin Anthony wrote:
>> I've been teaching myself list comprehension, and i've run across something
>> i'm not able to convert.
>>
>> here's the original code for matrix multiplcation
>>
>> retmatrix = Matrix(self.__row,other.__col)
>> for m in range(0,retmatrix.__row):
>> for n in range(0,retmatrix.__col):
>> product = 0
>> for p in range(1,self.__col+1):
>> product += (self.__matrix[m][p] * other.__matrix[p][n])
>> retmatrix.__matrix[m][n] = product
>>
>> Here is what i have so far:
>> retmatrix.__matrix = [[ product = product + (self.__matrix[m][p]*
>> other.__matrix[p][n])
>>  if product else self.__matrix[m][p]* other.__matrix[p][n])
>>  for p in range(0,self.col)
>>  for n in range(0,self.col)]
>>  for m in range(0,self.__row)]
>>
>> But i know that isn't correct, can someone nudge my in the right direction?
>>
>>
>
> The biggest thing to learn about list comprehensions is when not to use
> them.  I can't imagine how your latter version (even if correct) is
> clearer than the first.

I think he might be using the wrong function for a matrix
multiplication, not that it's not workable, but there are other
libraries like numpy that could help out.

I wouldn't use list comprehension for this, unless it might be several
lists that interact.
>
>
>
> --
>
> DaveA
>
> --
> http://mail.python.org/mailman/listinfo/python-list



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


Re: list comprehension question

2012-10-16 Thread Dwight Hutto
On Tue, Oct 16, 2012 at 10:13 PM, Dwight Hutto  wrote:
> On Tue, Oct 16, 2012 at 9:54 PM, Kevin Anthony
>  wrote:
>> I've been teaching myself list comprehension, and i've run across something
>> i'm not able to convert.
>>
>> here's the original code for matrix multiplcation
>>
>> retmatrix = Matrix(self.__row,other.__col)
>> for m in range(0,retmatrix.__row):
>> for n in range(0,retmatrix.__col):
>> product = 0
>> for p in range(1,self.__col+1):
>> product += (self.__matrix[m][p] * other.__matrix[p][n])
>> retmatrix.__matrix[m][n] = product
>>
>> Here is what i have so far:
>> retmatrix.__matrix = [[ product = product + (self.__matrix[m][p]*
>> other.__matrix[p][n])
>>  if product else self.__matrix[m][p]* other.__matrix[p][n])
>>  for p in range(0,self.col)
>>  for n in range(0,self.col)]
>>  for m in range(0,self.__row)]
>>
>> But i know that isn't correct, can someone nudge my in the right direction?
>>
>>
>> --
>> Thanks
>> Kevin Anthony
>> www.NoSideRacing.com
>>
>> Do you use Banshee?
>> Download the Community Extensions:
>> http://banshee.fm/download/extensions/
>>
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
> I did this a little while back for something else, but memories get
> jumbled up in these molecules of data I have floating around in my
> mind, but maybe this will put you on the right track.
>
>
> --

I know this doesn't answer the python question, but it will help you
algorithm out what you need to know.

I do lots of interdisciplinary research, so if this doesn't help, let
me know, and I'll take a refresher, and work up some code. Also, look
at numpy.
-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list comprehension question

2012-10-16 Thread Dave Angel
On 10/16/2012 09:54 PM, Kevin Anthony wrote:
> I've been teaching myself list comprehension, and i've run across something
> i'm not able to convert.
>
> here's the original code for matrix multiplcation
>
> retmatrix = Matrix(self.__row,other.__col)
> for m in range(0,retmatrix.__row):
> for n in range(0,retmatrix.__col):
> product = 0
> for p in range(1,self.__col+1):
> product += (self.__matrix[m][p] * other.__matrix[p][n])
> retmatrix.__matrix[m][n] = product
>
> Here is what i have so far:
> retmatrix.__matrix = [[ product = product + (self.__matrix[m][p]*
> other.__matrix[p][n])
>  if product else self.__matrix[m][p]* other.__matrix[p][n])
>  for p in range(0,self.col)
>  for n in range(0,self.col)]
>  for m in range(0,self.__row)]
>
> But i know that isn't correct, can someone nudge my in the right direction?
>
>

The biggest thing to learn about list comprehensions is when not to use
them.  I can't imagine how your latter version (even if correct) is
clearer than the first.



-- 

DaveA

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


Re: Tkinter how to access the widget by name

2012-10-16 Thread woooee
On Oct 14, 1:11 pm, Владимир Пылев  wrote:
> label = Label(frame, width = 40, text='text', name = 'name')
> ...
> name_='name'
> configure(name_)
> ...
> def configure(name_)
>         #And how can that be?
>         # At least let the text you want to change 

I do not understand your question, but I think you want something like

def configure(name):   ## note that a colon is required here
   name.configure(bg='green')
   #  or
   name['bg']='green'

label_1 = Label(frame, width = 40, text='text')
configure(label_1)
label_2 = Label(frame, width = 40, text='label_2')
configure(label_2)

If this is not what you want, post an example that is more specific.
-- 
http://mail.python.org/mailman/listinfo/python-list


list comprehension question

2012-10-16 Thread Kevin Anthony
I've been teaching myself list comprehension, and i've run across something
i'm not able to convert.

here's the original code for matrix multiplcation

retmatrix = Matrix(self.__row,other.__col)
for m in range(0,retmatrix.__row):
for n in range(0,retmatrix.__col):
product = 0
for p in range(1,self.__col+1):
product += (self.__matrix[m][p] * other.__matrix[p][n])
retmatrix.__matrix[m][n] = product

Here is what i have so far:
retmatrix.__matrix = [[ product = product + (self.__matrix[m][p]*
other.__matrix[p][n])
 if product else self.__matrix[m][p]* other.__matrix[p][n])
 for p in range(0,self.col)
 for n in range(0,self.col)]
 for m in range(0,self.__row)]

But i know that isn't correct, can someone nudge my in the right direction?


-- 
Thanks
Kevin Anthony
www.NoSideRacing.com

Do you use Banshee?
Download the Community Extensions:
http://banshee.fm/download/extensions/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: overriding equals operation

2012-10-16 Thread Dwight Hutto
On Tue, Oct 16, 2012 at 9:51 AM, Pradipto Banerjee
 wrote:
> I am trying to define class, where if I use a statement a = b, then instead 
> of "a" pointing to the same instance as "b", it should point to a copy of 
> "b", but I can't get it right.
>
> Currently, I have the following:
>
> 
>
> class myclass(object):
> def __init__(self, w3kschoolsname='')
> self.name = name
>
> def copy(self):
> newvar = myclass(self.name)
> return newvar
>
> def __eq__(self, other):
> if instance(other, myclass):
> return self == other.copy()
> return NotImplemented
> 
>
> Now if I try:
>
 a=myclass()
 a.name = 'test'
 b=a
 b.name
> 'test'
 b.name = 'test2'
 a.name
> 'test2'
>
> I wanted b=a to make a new copy of "a", but then when I assigned b.name = 
> 'test2', even a.name became 'test2'.
>
> How can I rectify my code to make the __eq__() behave like copy()?
>
> Thanks
>
>
>

If I'm understanding correctly(quick look at it), then write a new py
file and __import__ it if I'm remember correctly.

Use a secondary file to rewrite the existing nature of the python code
file, then import it, and utilize the remade secondary py file for
your usage..
-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


how to use pyODBC to connect to MySql ,please give me a sample

2012-10-16 Thread iMath

 host name : localhost
user name:root
 password:19910512
database name : shopping
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2012-10-16 Thread Andrew Cooper
On 16/10/2012 04:43, J wrote:
> Hi...
> 

> 
> So, what I REALLY want is to inject my start/stop markers into klogd
> rather than syslogd.  This will, I hope, give my markers kernel
> timestamps rather than syslog timestamps which are not as accurate.
> 
> So does anyone know of a way to do this?  Unfortunately, I've tried
> some searching but google doesn't like the term klog, and most of the
> hits involved injecting code or other things that are not related at
> all.
> 
> Or, if there's a better way to get accurate timestamps, what would that be?
> 

It is very easy (about 40 lines of C) to write a kernel module which
opens up an easy interface to use.

I wrote a kernel module (unimaginatively called uklog, for user-klog)
which exports /proc/printk/{alert thru debug}.  With this in place, any
(root, although this can be changed) userspace process can issue
messages into the kernel by opening the relevant file and writing to it.

Sadly, this is not useful on any system which is not your own, and is
also unlikely to be accepted upstream (although it is fantastically
useful for micro-vms with no root filesystems, where the kernel log is
the only form of logging, and the serial console is the only useful
method of communication.)

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


Re: OT Questions

2012-10-16 Thread Dwight Hutto
On Tue, Oct 16, 2012 at 1:47 PM, Walter Hurry  wrote:
> On Tue, 16 Oct 2012 11:23:09 -0600, Ian Kelly wrote:
>
>> My theory for a while now has been that Mr. Hutto is probably an
>> enterprising teenager
>
> My theory for a while now has been that Mr. Hutto belongs in the bozo bin.


Maybe you're a little too serious. From what I've seen, a little
clowning around makes days easier, and it's supposed to be good
natured discussion that just gets misconveyed in an email with no
personal contact.




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


Re: OT Questions

2012-10-16 Thread Dwight Hutto
On Tue, Oct 16, 2012 at 1:23 PM, Ian Kelly  wrote:
> On Tue, Oct 16, 2012 at 9:21 AM, Demian Brecht  wrote:
>> There's a small light somewhere deep down that says maybe this is just
>> someone quite misdirected. A brief search shows that he has multiple
>> domains, all with the same type of design. I would be hard pressed to think
>> that someone would go to that extent just to troll a list.
>>
>> Meh, maybe it's my good nature :P
>
> My theory for a while now has been that Mr. Hutto is probably an
> enterprising teenager.

Nope 33, with a bad history, and trying to reinvent myself. And my
nature is always shop talk, and messing around with the guys, and it's
never mean.

I'm a self educated individual, and I like to joke some, which doesn't
get conveyed when you're in an email/text conversation, and you can't
hear the tone or pitch of my voice joking with you.

That can lead to a misinterpretation of what's said.

His desire to build a web development company
> is sincere and should be encouraged, but his lack of experience

You have no clue about my other skill sets, and what I do, so get to
know me, and you'll see experience s that will blow your mind.

This comes from a former crip/tru soldier getting his life straight
instead of the other options I have available.

 is
> readily apparent, as is his rather crude behavior on list.

I'm working on toning down the smack talk, I'm just used to a little
witty back and forth with some seriously cruel individuals.

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


Re: OT Questions

2012-10-16 Thread Dwight Hutto
On Tue, Oct 16, 2012 at 11:53 AM, rusi  wrote:
> On Oct 16, 7:55 pm, Demian Brecht  wrote:
>> I'm not sure whether or not this is a troll, but I'll bite.
>
> Do trolls exist any more than pixies, elves, gnomes, unicorns?
> Trolling posts of course do... IOW:
>
>> There's a small light somewhere deep down that says maybe this is just
>> someone quite misdirected.

I've spet a lot of time alone working on things I like, and just
wanted to have some good critics come in without the bs that can go
on, and sometimes I sling a little mud at awhat seems to be a personal
attack.

>
> means giving the benefit of doubt and seems to me to be good policy
> (withing reasonable limits)
> --
> http://mail.python.org/mailman/listinfo/python-list



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


Re: OT Questions

2012-10-16 Thread Dwight Hutto
On Tue, Oct 16, 2012 at 11:13 AM, Jean-Michel Pichavant
 wrote:
> - Original Message -
>
> [snip a link to a 1980's personal gif based homepage]
>
>> Now having said all of that, if this is a troll, I feel rather
>> foolish.
>
> Search deep inside your heart, and you'll realize you already know the answer 
> to that question :o)
>
No I'm not a troll. I like to answer, as well as ask, and sometimes
things get heated, and you get called a name, and the name takes the
argument out of context sometimes.

You can't like everybody, and sometimes egos get in the way.

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


Re: OT Questions

2012-10-16 Thread Dwight Hutto
I'm not sure whether or not this is a troll, but I'll bite.

No, not a troll, I've been around these lists for a while, and a few
wild arguments stemming from both my ego, and some other programmer's
arrogance.
>
> If you're going to ask for people's opinions on your work, I would try to
> keep the negativity in a list to zero.

If a flame on you pops up, you sometimes fight fire with fire. There
are a lot of things that get mixed up. Like maybe a personal reply
instead of reply all, that everyone else missed, or didn't see another
thread in which the argument started.

 I'm relatively new to this list and
> the tirades that you've gone on have been childish at best.

You haven't been on lists long enough then to have seen some real
flame warts...no offense.

 Doing that and
> then turning around and asking for useful feedback (if you're genuinely
> looking for it) is not going to yield much.

It does from those who I trust as not going to go into rants, such as
I have, but mine are usually in response, and yes they do get nasty at
times.

>
> Now that that's over..
>
> I couldn't get to your oDesk profile, got an empty page. That *could* be
> caused by the dead zones that I'm hitting atm, but I gave up after a few
> tries.

It's there, and it's a starter portfolio for other freelance sites
looking for work.
>
> I then went to your website and here's what I can see from a glance. This
> isn't meant to be harsh or slag you personally, but learn what you're doing
> before you attempt to create a company to help others. If you *do* know what
> you're doing, use your site to showcase that. Nobody will hire someone with
> a business site like your current site:

It's in a design phase, and I'm asking the local experts to critique
it, and even be harsh.
>
> * You have a bloated, 50+MB gif serving your page contents. That's just bad
> for obvious reasons

It was meant as more of a commercial to show a little more umph in my
site presentation, and I'm working on reducing the size through
several different means.
.
> * There's no DOCTYPE declaration in your HTML.
> * You have s mixed in pre-
> * You don't have a  container

Working on it buddy.

> * You have embedded music. Not only is this a bad design choice from a UX
> perspective, but it's also causing the client to load more

I know this, and I'm trying to reduce it, but show something that's appealing.
.
> * You have *no* SEO

Not yet, and the graphic has no text for the web crawlers to parse,
which I'm aware of, as well as no meta tags

> * You have commented out HTML

This is the design phase, and that will be removed.

> * You don't have any design sense (not a personal attack, I don't have any
> either).

I kind of like my designs, and they're being refined through these
conversations.

>
> My suggestions:
> * Take courses (free or paid) on web development. Udacity has a few good
> ones.

I like w3schools.com, and I know that it's a rough draft, and so
should my critics.

> * Apply your learnings to your site. Showcase what you can do and what you
> know and what you can do.
> * Look for a designer partner, someone who can make your work visually
> appealing. The visuals are the first impression (after initial load times).

I like to work alone, and his is an attempt to get others in the OS
community to comment.

>
>
> Now having said all of that, if this is a troll, I feel rather foolish.

Only trolling for fish under the bridge...clients

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


Re: Aggressive language on python-list

2012-10-16 Thread Joshua Landau
First of all, I believe this is the *perfect* post to try and
keep discussion calm. If trusted members cannot keep a good tone of voice
and have an understanding (even if disagreeing) stance on a post
about aggressive language, it does not shine brightly as a message to
others.

On 16 October 2012 22:12,  wrote:

> On 10/16/2012 02:17 PM, Prasad, Ramit wrote:> Steven D'Aprano wrote:
> >> On Tue, 16 Oct 2012 09:27:48 -0700, rurpy wrote about trolls and dicks:
> >> If you ignore such posts, how will the poster know they are
> unacceptable?
> >
> > I agree completely. I was about to say that I was fine with meeting
> > known trolls with silence, but what happens when new or infrequent
> > readers see the troll's writing with no one objecting? Are they to
> > ignore the troll or assume that the list condones the troll's words?
>
> You do not give enough credit to people.  The vast majority
> of people are capable of recognizing offensive posts and
> recognizing that non-response to them is intentional.


I think you are only right up to a point. Whilst some messages are obvious
trolls, it is a well known phenomena that people respond emphatically to
even the most outrageous of posts, especially if they are new enough not to
know the culture we expect.


> I think it is absurd to think that most normal people will
> see such posts and conclude that all Python programmers
> agree with them.  (No time to look it up but I vaguely
> recall a long series of anti-semitic posts here that were
> largely ignored.  I've seen no evidence that there are
> people who brand the Python community as anti-semitic.)
>

These are a brilliant example of obvious spam. A quick GMail search for
"Jew" turned up a fair few spread posts that were definitely anti-Semitic.
However, they were posts that lacked any context and had nothing to relate
to Python, this list or anyone on this list. They were so obviously
irrelevant that it would be crazy for anyone to label the list with this.

If these posts were short responses like "Your code's just broken you
stupid Jew", then your point would be more easy to accept. I can imagine
(for it is *the internet*) that someone would take genuine offence and
label *sections* of the Python-List community as anti-semetic.

However, a response of "*Qxrlt* *is a known" + ("spammer" | "troll" |
"bot") to the OP (never talking to the troll for fear of baiting) is likely
to immediately alleviate any risk and cannot, as far as I can see, propose
any significant risk.

>From that point on, every post of theirs in the thread can be ignored
safely. Which is the goal, I guess.


I am going to go on record to say I agree with you that a warning cannot
oft change a troll's behaviour, and a talking to (of any kind) will likely
act as troll bait. However, this does not mean that silence is the best
option.

* Apologies to Qxrlt, whoever may have that pseudo-random character stream
as their nickname
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fwd: system tray or notification area in python

2012-10-16 Thread Christian Gollwitzer

Am 16.10.12 22:39, schrieb Daniel Fetchinson:

Hi folks,
So I thought I would write a brand new stand alone system tray or
notification area in python. I guess I need to use gtk bindings or
some such but don't really know what my options are.

Where would I start something like this?
Any pointers would be greatly appreciated!


Why not look at the source code of the current app your using to get
an idea how that application accomplishes said task?


I actually did that already it's using the C bindings of gtk.


I think you are mistaken - if its this one:
http://stalonetray.sourceforge.net/

I had a quick look into the sources, it does not use gtk at all, it uses 
low level X11 calls. Programming in this way is very tedious.



But I have zero experience with gui programming in python. So any
pointers would be much appreciated how to implement a system tray in
python. Gtk is I guess just one option, one could use other stuff from
python but I wouldn't know what the simplest approach is.


I'm not sure it is even possible. "Usual" GUI applications just need to 
request certain features from their window manager such as the setting 
the program icon or requesting a certain position on the screen. That is 
what is implemented in the usual toolits like Tk, QT, and gtk.


A window manager, on the other hand, must be able to recieve and 
interpret these messages. For a system tray, they are described here:


http://standards.freedesktop.org/systemtray-spec/systemtray-spec-0.3.html

I have not studied the whole interface of the aforementioned toolkits, 
but I suspect that there is no way around writing low level Xlib code in 
order to recieve these messages.


Don't take it wrong, but when you write that you have no experience with 
GUI programming, I'd start another projet first - I think you will have 
a tough way to succeed with this project.


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


RE: system tray or notification area in python

2012-10-16 Thread Prasad, Ramit
Daniel Fetchinson wrote:
> >> Hi folks,
> >>
> >> I'm using a stand alone window manager without gnome or kde or any
> >> other de. But I still would like to have a system tray or notification
> >> area and so far used stalonetray for this. Stalonetray is written in C
> >> and is a GTK application, works all right but sometimes it doesn't.
> >> For instance if it is killed and restarted icons don't come back, etc,
> >> etc, there are some quirks.
> >>
> >> So I thought I would write a brand new stand alone system tray or
> >> notification area in python. I guess I need to use gtk bindings or
> >> some such but don't really know what my options are.
> >>
> >> Where would I start something like this?
> >> Any pointers would be greatly appreciated!
> >>
> > Why not look at the source code of the current app your using to get
> > an idea how that application accomplishes said task?
> 
> I actually did that already it's using the C bindings of gtk.
> You might ask you I'm not modifying the code in order to achieve what
> I want, well, the answer is that I'd much rather prototype something
> like this in python than work immediately with gtk from C.
> 
> But I have zero experience with gui programming in python. So any
> pointers would be much appreciated how to implement a system tray in
> python. Gtk is I guess just one option, one could use other stuff from
> python but I wouldn't know what the simplest approach is.
> 
> 

I have used wxpython and thought it was powerful and reasonably easy 
to use. I have no experience with other Python frameworks but I know 
wxpython is a popular choice and I would guess it has an active community.

That is my two cents (or lowest denomination currency for your locale).

> 
> > You could always use raw X11 libs but leveraging something like Gtk or
> > Qt/KDE would probably be much easier.
> 

~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: Aggressive language on python-list

2012-10-16 Thread rurpy
On 10/16/2012 02:17 PM, Prasad, Ramit wrote:> Steven D'Aprano wrote:
>> On Tue, 16 Oct 2012 09:27:48 -0700, rurpy wrote about trolls and dicks:
>> 
>> > The best advise is to ignore such posts and encourage others to do the
>> > same.
>> 
>> If you ignore such posts, how will the poster know they are unacceptable?
>> 
>> How should somebody distinguish between "I am being shunned for acting
>> like a dick", and "I have not received any responses because nobody has
>> anything to add"?
>> 
>> If I believe that your behaviour ("giving lousy advice") is causing great
>> harm to this community, and *I don't say anything*, how will you know to
>> change your behaviour? How will others know that I do not agree with your
>> advice?
> 
> I agree completely. I was about to say that I was fine with meeting
> known trolls with silence, but what happens when new or infrequent 
> readers see the troll's writing with no one objecting? Are they to
> ignore the troll or assume that the list condones the troll's words?

You do not give enough credit to people.  The vast majority 
of people are capable of recognizing offensive posts and 
recognizing that non-response to them is intentional.  I 
think it is absurd to think that most normal people will
see such posts and conclude that all Python programmers 
agree with them.  (No time to look it up but I vaguely
recall a long series of anti-semitic posts here that were 
largely ignored.  I've seen no evidence that there are 
people who brand the Python community as anti-semitic.)

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


Re: Aggressive language on python-list

2012-10-16 Thread rurpy
On 10/16/2012 10:49 AM, Steven D'Aprano wrote:
> > On Tue, 16 Oct 2012 09:27:48 -0700, rurpy wrote about trolls and dicks:

No, I wrote about trolls.  "dicks" is a highly emotive and 
almost totally subjective word that I would not use in a
rational discussion.  Perhaps you were trying to be amusing?

>> >> The best advise is to ignore such posts and encourage others to do the
>> >> same.
> > 
> > If you ignore such posts, how will the poster know they are unacceptable?

Do you really think that in the vast majority of cases that
the poster is blithely unaware of the inflammatory nature 
of their post?  The whole point of trolling is to generate
responses by posting something inflammatory.  It sounds to
me like your view is that most such posts are made by people 
who are simply brand new to the internet (or at least the 
civilized parts of it) and thus, when their error is pointed 
out, will say thanks and change their ways.
 
> > How should somebody distinguish between "I am being shunned for acting 
> > like a dick", and "I have not received any responses because nobody has 
> > anything to add"?

Because you sent them private email telling them that?  (And
if you can't do that, maybe you should take it as a hint that
they're not particularly interested in your "help"?)

> > If I believe that your behaviour ("giving lousy advice") is causing great 
> > harm to this community, and *I don't say anything*, how will you know to 
> > change your behaviour? 

If that was how you thought, then you would be someone I hope 
would follow my advice.  Because you would clearly seem to be 
unable to distinguish between difference of opinion on a 
subject relevant to the newsgroup, and inflammatory trolling.  
Further you see the situation in extreme terms ("*great 
harm*") and one in which only a single point of view (your's) 
is acceptable.  You would be bordering on delusional by 
thinking your post would somehow change my "behavior".  

But even if you had a more rational response and saved 
that reaction for actual trolling and not someone who 
simply disagreed with you, I ask again, what makes you 
think your response will change that troll's behavior,
when in actuality, your kind of response is exactly what
most trolls hope to elicit?  Did it help in the case I
mentioned?

> > How will others know that I do not agree with your 
> > advice?

Why is it so important to you that I and others know what 
you think?  Since you are (usually) a reasonable person I
don't need to read your explicit pronouncement to assume
that you disagree with some repugnant post.

If it were possible to somehow have a single, reasonable
response generated to an offensive post, that would be great.
But I don't think that is possible.  Multiple people will 
feel the need to take on that duty.  Others will feel the
response is not strong enough or doesn't represent their
personal take and post their responses.  Some will respond
righteously to non-offensive posts.  (The use of "troll"
as a synonym for "I/we don't agree with you" is quite 
noticeable in this group.)  The perp will inevitably
followup with more offensive posts in response.  This 
is how things have worked since the invention of mailing
lists and why "don't feed the trolls" has served fairly
well for three decades.

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


Re: [on topic] Re: readline trick needed

2012-10-16 Thread Ned Deily
In article , Peter Otten <__pete...@web.de> 
wrote:
> Ned Deily wrote:
> > Keep in mind that the Python readline module may be linked to either the
> > GPL-licensed GNU readline or the BSD-licensed editline (libedit) library
> > (the default on newer OS X systems and probably on *BSD systems) and
> > they have different command strings.  Note the warning here:
> > 
> > http://docs.python.org/py3k/library/readline.html
> 
> I think you are a Mac user. If so, can the snippet I posted be generalised 
> to work with libedit?

Isn't it hairy enough??

Here's how to make tab complete work with both; it gives an idea of the 
libedit commands:

 import rlcompleter
 if 'libedit' in readline.__doc__:
 readline.parse_and_bind("bind ^I rl_complete")
 else:  # GNU readline format
 readline.parse_and_bind("tab: complete")

The documentation of the command syntax is in the .editrc man pages, for 
example:

https://developer.apple.com/library/mac/#documentation/Darwin/Reference/M
anPages/man5/editrc.5.html
 
> > Or it may not be linked with either. 
> OK, change "no warranties" to "absolutely no warranties" ;)

Good idea.

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

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


RE: Aggressive language on python-list

2012-10-16 Thread Prasad, Ramit
Steven D'Aprano wrote:
> On Tue, 16 Oct 2012 09:27:48 -0700, rurpy wrote about trolls and dicks:
> 
> > The best advise is to ignore such posts and encourage others to do the
> > same.
> 
> If you ignore such posts, how will the poster know they are unacceptable?
> 
> How should somebody distinguish between "I am being shunned for acting
> like a dick", and "I have not received any responses because nobody has
> anything to add"?
> 
> If I believe that your behaviour ("giving lousy advice") is causing great
> harm to this community, and *I don't say anything*, how will you know to
> change your behaviour? How will others know that I do not agree with your
> advice?
> 
> 

I agree completely. I was about to say that I was fine with meeting
known trolls with silence, but what happens when new or infrequent 
readers see the troll's writing with no one objecting? Are they to
ignore the troll or assume that the list condones the troll's words?

~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


Fwd: system tray or notification area in python

2012-10-16 Thread Daniel Fetchinson
>> Hi folks,
>>
>> I'm using a stand alone window manager without gnome or kde or any
>> other de. But I still would like to have a system tray or notification
>> area and so far used stalonetray for this. Stalonetray is written in C
>> and is a GTK application, works all right but sometimes it doesn't.
>> For instance if it is killed and restarted icons don't come back, etc,
>> etc, there are some quirks.
>>
>> So I thought I would write a brand new stand alone system tray or
>> notification area in python. I guess I need to use gtk bindings or
>> some such but don't really know what my options are.
>>
>> Where would I start something like this?
>> Any pointers would be greatly appreciated!
>>
> Why not look at the source code of the current app your using to get
> an idea how that application accomplishes said task?

I actually did that already it's using the C bindings of gtk.
You might ask you I'm not modifying the code in order to achieve what
I want, well, the answer is that I'd much rather prototype something
like this in python than work immediately with gtk from C.

But I have zero experience with gui programming in python. So any
pointers would be much appreciated how to implement a system tray in
python. Gtk is I guess just one option, one could use other stuff from
python but I wouldn't know what the simplest approach is.

Cheers,
Daniel


> You could always use raw X11 libs but leveraging something like Gtk or
> Qt/KDE would probably be much easier.



-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown



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


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

2012-10-16 Thread Jerry Peters
J  wrote:
> Hi...
> 
> I have a bit of code that does the following:
> 
> uses the syslog module to inject a LOG_INFO message into the syslog on
> my linux machine
> runs a suspend/resume cycle
> uses the syslog module to inkect a LOG_INFO message marking the end of test.
> 
> Then I parse everything between the start and stop markers for certain
> items that the Linux kernel logs during a suspend and resume cycle.
> 
> But my  "resume complete" timing is not as accurate as it could be.
> The problem with doing it this way is that while I can find definite
> kernel messages that mark various points in the suspend/resume cycle,
> the final message when the kernel is done resuming is NOT the point I
> actually want to mark.
> 
> Instead, the end point I want is the time of the ending marker itself,
> as this happens after certain other things are done such as resumption
> of networking services.
> 
> Here's the problem.  I can't just use syslog timestamps.  The reason
> is that the syslog timestamps are only indicative of when messages are
> written to syslog via syslogd.  The kernel timestamps are different.
> For example, the following bits of log are taken from the time the
> test starts until the end of the "going to sleep" kernel messages.
> First, note that there's a 5 second difference between the START
> marker and the first kernel message.  Next, look at the kernel
> timestamps.  The total real time to suspend starts at 421320.380947
> and ends at 421322.386355, around 2 seconds later, where the log
> messages themselves all state that the events occurred at the same
> time.
> 
> Oct 15 10:24:19 klaatu sleep_test: ---SLEEP TEST START 1350296656---
> Oct 15 10:25:24 klaatu kernel: [421320.380947] PM: Syncing filesystems ... 
> done.
> Oct 15 10:25:24 klaatu kernel: [421320.391282] PM: Preparing system
> for mem sleep
> [SNIP]
> Oct 15 10:25:24 klaatu kernel: [421322.282943] Broke affinity for irq 23
> Oct 15 10:25:24 klaatu kernel: [421322.386355] CPU 7 is now offline
> 
> So, what I REALLY want is to inject my start/stop markers into klogd
> rather than syslogd.  This will, I hope, give my markers kernel
> timestamps rather than syslog timestamps which are not as accurate.
> 
> So does anyone know of a way to do this?  Unfortunately, I've tried
> some searching but google doesn't like the term klog, and most of the
> hits involved injecting code or other things that are not related at
> all.
> 
> Or, if there's a better way to get accurate timestamps, what would that be?


Take a look at /dev/kmsg, I *believe* it's the way various boot
logging programs inject application type messages into the kernel boot
up message stream.

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


Re: system tray or notification area in python

2012-10-16 Thread Rodrick Brown
On Oct 16, 2012, at 4:14 PM, Daniel Fetchinson
 wrote:

> Hi folks,
>
> I'm using a stand alone window manager without gnome or kde or any
> other de. But I still would like to have a system tray or notification
> area and so far used stalonetray for this. Stalonetray is written in C
> and is a GTK application, works all right but sometimes it doesn't.
> For instance if it is killed and restarted icons don't come back, etc,
> etc, there are some quirks.
>
> So I thought I would write a brand new stand alone system tray or
> notification area in python. I guess I need to use gtk bindings or
> some such but don't really know what my options are.
>
> Where would I start something like this?
> Any pointers would be greatly appreciated!
>
Why not look at the source code of the current app your using to get
an idea how that application accomplishes said task?

You could always use raw X11 libs but leveraging something like Gtk or
Qt/KDE would probably be much easier.

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


system tray or notification area in python

2012-10-16 Thread Daniel Fetchinson
Hi folks,

I'm using a stand alone window manager without gnome or kde or any
other de. But I still would like to have a system tray or notification
area and so far used stalonetray for this. Stalonetray is written in C
and is a GTK application, works all right but sometimes it doesn't.
For instance if it is killed and restarted icons don't come back, etc,
etc, there are some quirks.

So I thought I would write a brand new stand alone system tray or
notification area in python. I guess I need to use gtk bindings or
some such but don't really know what my options are.

Where would I start something like this?
Any pointers would be greatly appreciated!

Cheers,
Daniel


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


Re: Providing a Python wrapper to a C++ type.

2012-10-16 Thread Christian Gollwitzer

Am 16.10.12 18:42, schrieb Evan Driscoll:

For instance, I used it to wrap the OS's opendir/readdir
(FindFirstFile/FindNextFile) functions: I just wrote a bit of code using
Cython's extensions, and I get a module I can import and use as normal.


Well, but for an existing library in C++ possibly SWIG will be the 
easiest way to go; since you already have a header file, it might be 
enough to do


swig -python -c++ myheader.hpp

to get the wrappers generated. This works well in simple cases. For 
complicated cases like trying to wrap large template libraries like STL 
or Boost, it is also necessary to twiddle with SWIGs interface language. 
In many cases, however, this can be #ifdef'ed in the header file itself, 
therefore it is easy to keep the interface in sync with the class library.


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


Re: OT Questions

2012-10-16 Thread Walter Hurry
On Tue, 16 Oct 2012 11:23:09 -0600, Ian Kelly wrote:

> My theory for a while now has been that Mr. Hutto is probably an
> enterprising teenager

My theory for a while now has been that Mr. Hutto belongs in the bozo bin.

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


Client Needs at Network Engineer at Germantown,MD

2012-10-16 Thread ram dev
Good Day,
We have an urgent Contract Opening in  Germantown, MD.

Looking forward to submit your resume for below mentioned Requirement…
If you are interested, Please forward your latest resume along with location 
and pay rate details to  r...@tech-netinc.com



Job Title:  Network Engineer
Location:  Germantown,MD
Duration: 6+ months

 Position Details:
Client is looking for a Network Engineer to 
join a multi-member / multi-region team which supports a Global Enterprise 
Network consisting of more than 50 sites. The successful candidate will engage 
with a Global team supporting systems and tools which include Cisco and HP 
networking and security systems, Blue Coat proxies, Juniper and Cisco SSL VPN 
appliances, Cisco and F5 load balances, H.323 and SIP voice gateways, Riverbed 
optimization and analysis appliances and management tools such as SPLUNK, Solar 
Winds Orion and TACACS+. 
Principal duties and responsibilities may include, but are not limited to: 
• Participate in rotating on-call coverage (as an escalation point for Tier 2) 
• Identify, diagnose, and resolve complex network problems 
• Assist application teams to diagnose and resolve performance issues over the 
network using sniffing tools (i.e. wire shark) 
• Able to travel occasionally for special projects 
• Implement, maintain and enhance network management tools (i.e. Riverbed 
Cascade, SPLUNK, Solar Winds Orion, etc…) 
• Review project specifications and make design/implementation recommendations 
for improvements 
• Escalation point for incident, change, and service request tickets 
• Preparation of proposals and solution presentations 
• Act as a level 3 support for firewalls, load balancers, routing, and 
switching. Work with technical group to resolve issues in a timely manner 
• Mentor and knowledge sharing (training) for Tier 2, Tier 1, desk side and 
helpdesk support staff 
• Submit network level changes and provide appropriate level of coordination 
along with implementation.
• Maintain knowledge of the network environment and sufficient familiarity with 
business/application/systems 
• Perform work in an ethical manner, and act at all times with a business 
professional manner

Required Qualifications:
• Minimum eight (8) years networking support for medium to large 
networks 
• Have senior/expert knowledge of routing and switching with Cisco and HP 
hardware/software. 
• Have senior/expert knowledge of Cisco ASA / ACE / ACS / TACACS+ / NCS, 
Juniper, and F5 
• Have senior/expert knowledge of ACE and F5 load balancing technologies. 
• Capable of performing packet level analysis. 
• Have senior/expert knowledge of Cisco Router suite of products (2900/3800, 
3900/2900, ASR, etc.) 
• Have senior/expert knowledge of Cisco Switch suite of products (6500, 4500, 
4900, 3750, etc.) 
• Have senior/expert knowledge of WAN technologies: Frame Relay, ATM, T3, MPLS, 
MetroE 
• Have senior/expert knowledge of Internet and networking technologies such as 
DNS, SMTP, SNMP, NTP. 
• Ability to understand and adhere to systems security and control procedures 
in accordance with departmental, vendor standards and regulatory bodies 
• Knowledge of network technologies such as, TCP/IP protocol, Layer 2 Spanning 
Tree, Layer 3 routing (EIGRP, BGP, OSPF), Quality of Services, DNS, DHCP, SNMP 
• Good knowledge of IP Telephony 
• Good Knowledge of Server Virtualization (i.e. VM Ware) and networking 
requirements to support 
• Have senior/expert knowledge of network cabling standards and wireless 
network technologies 
• Have senior/expert knowledge of enterprise network management tools such as 
Cisco Works, HP Open view, Solar Winds 
• Provide leadership to junior staff 
• Must be able to create and update documentation with Visio, Excel and Word 
• At least 2 years in a team lead or technical project management role, with 
experience in: 
o Ability to oversee and lead vendors and other network department resources 
o Ability to interact with other departments such as facilities 
• Ability to work independently and provide timely status updates. 
• Good oral and written communications skills. 
• Ability to handle multi-tasking and frequently changing priorities. 
• Cisco Certifications a plus 
• Familiarity with ITIL processes a plus


Thanks,

Ram Dev
Recruiter
Tech-Net Inc.
Tel: 916-458-4390 Ext 102
Email: r...@tech-netinc.com 
Ym: vramde...@yahoo.com
URL: www.tech-netinc.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: overriding equals operation

2012-10-16 Thread Nobody
On Tue, 16 Oct 2012 08:51:46 -0500, Pradipto Banerjee wrote:

> I am trying to define class, where if I use a statement a = b, then
> instead of "a" pointing to the same instance as "b", it should point to a
> copy of "b", but I can't get it right.

It cannot be done.

Name binding ("variable = value") is a language primitive; it is not
delegated to the object on the LHS (if there even is one; the name doesn't
have to exist at the point that the statement is executed).

You'll have to change the syntax to something which is delegated to
objects, e.g. "a[:] = b" will call "a.__setitem__(slice(None), b)"

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


Re: cx_Oracle clause IN using a variable

2012-10-16 Thread Hans Mulder
On 16/10/12 15:41:58, Beppe wrote:
> Hi all,
> I don't know if it is the correct place to set this question, however,
> I'm using cx_Oracle to query an Oracle database.
> I've a problem to use the IN clause with a variable.
> My statement is 
> 
> sql = "SELECT field1,field2,field3
> FROM my_table
> WHERE field_3 IN (:arg_1)"
> 
> where arg_1 is retrive by a dictionary
> that is build so
> 
>  my_dict = {'location':"X",
> 'oracle_user':'user',
> 'oracle_password':'pass',
> 'dsn':'dsn',
> 'mailto':'some...@somewhere.org',
> 'codes':"CNI,CNP"}
> 
> args = (dict['codes'],)
>
>  
> con = cx_Oracle.connect(my_dict["oracle_user"],
>  my_dict["oracle_password"],
>  my_dict["dsn"])
>  
> cur = con.cursor()
> cur.execute(sql,args)
> rs =  cur.fetchall()   
> 
> but it doesn't work in the sense that doesn't return anything
> 
> If i use the statment without variable 
> 
> SELECT field1,field2,field3
> FROM my_table
> WHERE field_3 IN ('CNI','CNP')
> 
> the query works
> 
> what is wrong?

You only have a single placeholder variable,
so your statement is equivalent to

SELECT field1,field2,field3
FROM my_table
WHERE field_3 IN ('CNI,CNP')

Presumably 'CNI,CNP' is not a valid value for field_3,
thus your query finds no records.

> suggestions?

To verify that you have the correct syntax, try it
with a single value first:

my_dict = {'location':"X",
'oracle_user':'user',
'oracle_password':'pass',
'dsn':'dsn',
'mailto':'some...@somewhere.org',
'codes':"CNI"}

It that produces some of the records you want, then the
question is really: can you somehow pass a list of values
via a single placeholder variable?

I'm, not a cx_Oracle expert, but I think the answer is "no".


If you want to pass exactly two values, then the work-around
would be to pass them in separate variables:

my_dict = {'location':"X",
'oracle_user':'user',
'oracle_password':'pass',
'dsn':'dsn',
'mailto':'some...@somewhere.org',
'code1':"CNI",
'code2':"CNP"}

sql = """SELECT field1,field2,field3
 FROM my_table
 WHERE field_3 IN (:arg_1, :arg_2)"""
args = (my_dict['code1'],my_dict['code2'])


If the number of codes can vary, you'll have to generate a
query with the correct number of placholders in it.  Mabye
something like this (untested):

my_dict = {'location':"X",
'oracle_user':'user',
'oracle_password':'pass',
'dsn':'dsn',
'mailto':'some...@somewhere.org',
'codes':"Ornhgvshy,vf,orggre,guna,htyl"}


args = my_dict['codes'].split(",")
placeholders = ','.join(":x%d" % i for i,_ in enumerate(args))

sql = """SELECT field1,field2,field3
 FROM my_table
 WHERE field_3 IN (%s)""" % placeholders

con = cx_Oracle.connect(my_dict["oracle_user"],
 my_dict["oracle_password"],
 my_dict["dsn"])

cur = con.cursor()
cur.execute(sql,args)
rs =  cur.fetchall()


Hope this helps,

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


Re: OT Questions

2012-10-16 Thread Ian Kelly
On Tue, Oct 16, 2012 at 9:21 AM, Demian Brecht  wrote:
> There's a small light somewhere deep down that says maybe this is just
> someone quite misdirected. A brief search shows that he has multiple
> domains, all with the same type of design. I would be hard pressed to think
> that someone would go to that extent just to troll a list.
>
> Meh, maybe it's my good nature :P

My theory for a while now has been that Mr. Hutto is probably an
enterprising teenager.  His desire to build a web development company
is sincere and should be encouraged, but his lack of experience is
readily apparent, as is his rather crude behavior on list.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cx_Oracle clause IN using a variable

2012-10-16 Thread Ian Kelly
On Tue, Oct 16, 2012 at 7:41 AM, Beppe  wrote:
> Hi all,
> I don't know if it is the correct place to set this question, however,

The best place to ask questions about cx_Oracle would be the
cx-oracle-users mailing list.

> what is wrong?
> suggestions?

With the bind parameter you're only passing in a single string, so
your query is effectively equivalent to:

SELECT field1,field2,field3
FROM my_table
WHERE field_3 IN ('CNI,CNP')

You can't pass an actual list into a bind parameter the way that you
would like.  You need to use a separate parameter for each item in the
list.  This may mean constructing the query dynamically:

in_vars = ','.join(':%d' % i for i in xrange(len(sequence_of_args)))

sql = """
SELECT field1,field2,field3
FROM my_table
WHERE field_3 IN (%s)
""" % in_vars

cursor.execute(sql, sequence_of_args)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: Providing a Python wrapper to a C++ type.

2012-10-16 Thread Evan Driscoll
[Stefan gave part of an answer here, but I've got an addition too.]

On 10/16/2012 6:46 AM, Marco Nawijn wrote:
> I never worked with Cython (but I know it is very powerful and interesting) 
> but in my mind there are slight differences in usage scenario between e.g. 
> Boost Python and Cython. For me the idea of Cython is that your main code is 
> in Python, but you want to improve the performance of specific parts of the 
> code. In that case, Cython is the way to go. In case of Boost Python, the 
> scenario for me is that you have a main program/library in C++, but you want 
> to be able use the functionality from Python. 
> 
> Do you agree with this view?

Sort of, but sort of not. I've only used Cython a little bit, but it
seems to work equally well if you want to write a C module for some
reason (e.g. to interface with existing C code) but don't want to deal
with the standard CPython C API directly.

For instance, I used it to wrap the OS's opendir/readdir
(FindFirstFile/FindNextFile) functions: I just wrote a bit of code using
Cython's extensions, and I get a module I can import and use as normal.
I certainly didn't do it for speed, I did it because it seemed like a
reasonable way to get access to those APIs. (ctypes was insufficient for
my needs.)

So wrapping a C++ class using Cython also seems pretty natural to me,
assuming that Cython does OK with C++ and isn't restricted to C (which I
have no idea about).

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


Re: Aggressive language on python-list

2012-10-16 Thread Steven D'Aprano
On Tue, 16 Oct 2012 09:27:48 -0700, rurpy wrote about trolls and dicks:

> The best advise is to ignore such posts and encourage others to do the
> same.

If you ignore such posts, how will the poster know they are unacceptable?

How should somebody distinguish between "I am being shunned for acting 
like a dick", and "I have not received any responses because nobody has 
anything to add"?

If I believe that your behaviour ("giving lousy advice") is causing great 
harm to this community, and *I don't say anything*, how will you know to 
change your behaviour? How will others know that I do not agree with your 
advice?


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


RE: Fastest web framework

2012-10-16 Thread Andriy Kornatskyy

Demian,

Thank you, see below.

> I think that my first batch of questions were slightly out of context,
> mostly due to a lack of caffeine first thing in the morning. My
> understanding at the time was that your "an answer to effectivity" was,
> in fact, a list of highlights for wheezy.web (which is why I asked the
> questions I did). Having said that..
>
> > The initial decisions taken while building a project might be wrong.
> Due to continues backward compatibility, you can not change them even
> you wish.
>
> You can always deprecate old functionality in favor of new solutions.
> I'd be hard pressed to find a reason to find a reason why something
> *can't* be deprecated. It may not be easy at times, but it should always
> be doable.

And that is the problem. Some can not deprecate and die (see pylons, now 
pyramid). Some can not die nor deprecate (see django).

> > That glue is usability case: recommendation how to use it with one or
> the other.
>
> As long as your framework doesn't require you to fight with it in order
> to use another solution. One of my early gripes with Django for example
> (ages ago) was that it felt like I had to fight the framework in order
> to introduce functionality that wasn't natively supported.
>
> > For you, personally, let me point this again. N.P.
> >
> > Here is how: use content caching with cache dependency. Read more:
> > http://packages.python.org/wheezy.http/userguide.html#content-cache
>
> It doesn't matter if you're using cached content or not. It will *not*
> be as fast as a hard-coded, simple response (not that a static,
> hard-coded response is the way to go obviously). I don't think I have to
> get into the details about I/O. My point is simply that the statement
> that a database driven site (cached content or not), *can not* be as
> fast as a "hello world" app. My comment may be construed as being
> nit-picky, but I thought it was worth calling out due to the
> matter-of-fact wording that you used.

It does. There is certain level after which performance of `hello world` will 
not differ from real world application. The hardware I used got that limit at 
22-24K per second. That is why I made isolated benchmarks. See difference 
between wsgi sample and others.

http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html

> On a somewhat unrelated note, I caught a minor typo in the content-cache
> docs:
>
> "Since there is no heavy processing and just simple operation to get an
> item from cache it should be supper fast"
>
> I don't know about you, but my supper generally isn't fast ;)

You will see. Thanks. supper => super ;-)

Somewhat later in a week there will be another benchmark for... caching.

Take care.

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


Re: Aggressive language on python-list

2012-10-16 Thread rurpy
On 10/14/2012 10:36 PM, alex23 wrote:> On Oct 15, 1:22 pm, ru...@yahoo.com 
wrote:
>> Thus when a member of this esteemed group
>> was recently attacked as racist, for punning another member's
>> name when responding somewhat heatedly,
> 
> Again, there is a difference between "attacking" someone "as racist"
> and *criticising* their *comments* as *possibly* racist. When the
> person whose name was being punned said that they themselves were
> unsure whether it was intended as a racial attack, then the behaviour
> was worth commenting on.

I just went back and reread what you and some others wrote
to make sure I was not misremembering and am comfortable 
sticking with my description.  (FTR, your initial response 
was "Please, don't be a dick.")

My intent was not to reargue that issue but to point out 
that different people have differing ideas on what is 
"acceptable" and "unacceptable" here and that if Ben 
Finney's advice to respond (in moderation) whenever one 
reads an "unacceptable" opinion is taken, one will create 
an environment in which troll's will flourish.

The best advise is to ignore such posts and encourage 
others to do the same.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Neo4j] ANN: python-blueprints, printemps and printemps client

2012-10-16 Thread Amirouche Boubekki
Héllo Javier,

2012/10/16 Javier de la Rosa 

> Do you need Java [1] to run any of them? There is another alternative
> called pyblueprints [2] through REST interface.
>
> [1]
> http://pyjnius.readthedocs.org/en/latest/installation.html#installation
> [2] https://github.com/escalant3/pyblueprints


Yes it uses Java with Jnius  to make it
possible. Printemps makes it possible to have the a server and a client but
it's probably a better idea to use something like pyblueprints since there
is only one database thread.

Regards,

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


Re: Fastest web framework

2012-10-16 Thread Demian Brecht

On 10/16/2012 7:47 AM, Andriy Kornatskyy wrote:
I think that my first batch of questions were slightly out of context, 
mostly due to a lack of caffeine first thing in the morning. My 
understanding at the time was that your "an answer to effectivity" was, 
in fact, a list of highlights for wheezy.web (which is why I asked the 
questions I did). Having said that..


> The initial decisions taken while building a project might be wrong. 
Due to continues backward compatibility, you can not change them even 
you wish.


You can always deprecate old functionality in favor of new solutions. 
I'd be hard pressed to find a reason to find a reason why something 
*can't* be deprecated. It may not be easy at times, but it should always 
be doable.


> That glue is usability case: recommendation how to use it with one or 
the other.


As long as your framework doesn't require you to fight with it in order 
to use another solution. One of my early gripes with Django for example 
(ages ago) was that it felt like I had to fight the framework in order 
to introduce functionality that wasn't natively supported.


> For you, personally, let me point this again. N.P.
>
> Here is how: use content caching with cache dependency. Read more:
> http://packages.python.org/wheezy.http/userguide.html#content-cache

It doesn't matter if you're using cached content or not. It will *not* 
be as fast as a hard-coded, simple response (not that a static, 
hard-coded response is the way to go obviously). I don't think I have to 
get into the details about I/O. My point is simply that the statement 
that a database driven site (cached content or not), *can not* be as 
fast as a "hello world" app. My comment may be construed as being 
nit-picky, but I thought it was worth calling out due to the 
matter-of-fact wording that you used.


On a somewhat unrelated note, I caught a minor typo in the content-cache 
docs:


"Since there is no heavy processing and just simple operation to get an 
item from cache it should be supper fast"


I don't know about you, but my supper generally isn't fast ;)
--
http://mail.python.org/mailman/listinfo/python-list


Re: OT Questions

2012-10-16 Thread rusi
On Oct 16, 7:55 pm, Demian Brecht  wrote:
> I'm not sure whether or not this is a troll, but I'll bite.

Do trolls exist any more than pixies, elves, gnomes, unicorns?
Trolling posts of course do... IOW:

> There's a small light somewhere deep down that says maybe this is just
> someone quite misdirected.

means giving the benefit of doubt and seems to me to be good policy
(withing reasonable limits)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT Questions

2012-10-16 Thread Demian Brecht

On 10/16/2012 8:13 AM, Jean-Michel Pichavant wrote:

Search deep inside your heart, and you'll realize you already know the answer 
to that question :o)

JM


There's a small light somewhere deep down that says maybe this is just 
someone quite misdirected. A brief search shows that he has multiple 
domains, all with the same type of design. I would be hard pressed to 
think that someone would go to that extent just to troll a list.


Meh, maybe it's my good nature :P
--
http://mail.python.org/mailman/listinfo/python-list


Re: [off topic], was Re: [on topic] Re: readline trick needed

2012-10-16 Thread Dwight Hutto
On Tue, Oct 16, 2012 at 10:36 AM, Peter Otten <__pete...@web.de> wrote:
> Dwight Hutto wrote:
>
> I knew I'd eventually regret putting "on topic" into the subject...

I didn't write that. If you're referring to OT, it means Off Topic,
and a response would be appreciated. And you can call me David, I go
by my middle name.
>
> Well done, Dwight.
>
> --
> http://mail.python.org/mailman/listinfo/python-list



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


Re: OT Questions

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

[snip a link to a 1980's personal gif based homepage]

> Now having said all of that, if this is a troll, I feel rather
> foolish.

Search deep inside your heart, and you'll realize you already know the answer 
to that question :o)

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


Re: Which book is the best?

2012-10-16 Thread Demian Brecht

On 10/15/2012 9:27 PM, 老爷 wrote:

I have strong c++ development experience.  But now I want to study the
python to do some windows setting task, such as editing file, changing
the system setting, doing some network processing.  Please help me which
book is the best?
Thanks.




If you're already a seasoned developer, nothing beats the official 
Python docs (http://python.org/doc/). I find most books to be filled 
with unnecessary narratives. The Python documentation is relatively 
terse and very well organized. As such, it'll get you off to the races 
in no time.


One of the many beautiful things about Python is the interactive help:

$python
>>> import re
>>> help(re)

You may also want to take a read through this:

$python
>>> import this

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


Re: OT Questions

2012-10-16 Thread Demian Brecht

On 10/15/2012 9:05 PM, Dwight Hutto wrote:

Like a lot of people here, I'm trying to build a web development business.
I'm starting off by building a profile on a freelance site.

I would like some honest opinions(don't be too harsh), about my approach.
I'm looking for a team effort to analyze my marketability.

This is just my prototype freelance portfolio:

https://www.odesk.com/users/~01710ac049863018eb



I'm not sure whether or not this is a troll, but I'll bite.

If you're going to ask for people's opinions on your work, I would try 
to keep the negativity in a list to zero. I'm relatively new to this 
list and the tirades that you've gone on have been childish at best. 
Doing that and then turning around and asking for useful feedback (if 
you're genuinely looking for it) is not going to yield much.


Now that that's over..

I couldn't get to your oDesk profile, got an empty page. That *could* be 
caused by the dead zones that I'm hitting atm, but I gave up after a few 
tries.


I then went to your website and here's what I can see from a glance. 
This isn't meant to be harsh or slag you personally, but learn what 
you're doing before you attempt to create a company to help others. If 
you *do* know what you're doing, use your site to showcase that. Nobody 
will hire someone with a business site like your current site:


* You have a bloated, 50+MB gif serving your page contents. That's just 
bad for obvious reasons.

* There's no DOCTYPE declaration in your HTML.
* You have s mixed in pre-
* You don't have a  container
* You have embedded music. Not only is this a bad design choice from a 
UX perspective, but it's also causing the client to load more.

* You have *no* SEO
* You have commented out HTML
* You don't have any design sense (not a personal attack, I don't have 
any either).


My suggestions:
* Take courses (free or paid) on web development. Udacity has a few good 
ones.
* Apply your learnings to your site. Showcase what you can do and what 
you know and what you can do.
* Look for a designer partner, someone who can make your work visually 
appealing. The visuals are the first impression (after initial load times).



Now having said all of that, if this is a troll, I feel rather foolish.
--
http://mail.python.org/mailman/listinfo/python-list


RE: Fastest web framework

2012-10-16 Thread Andriy Kornatskyy

Demian,

Thank you, I appreciate your input. See below.

> > Performance and effectivity are related metrics. Longer 
feature list can not explain why it less effective. An answer to 
effectivity question might be related to:
> > - code quality (we have PEP8)
>
> Any static code analysis such as pylint or pyflakes?

Yep, good start with any of those.

> > - architectural decisions taken
>
> What (sample of) decisions? How do they differ from other frameworks?
> How will they make my life better?

The initial decisions taken while building a project might be wrong. Due to 
continues backward compatibility, you can not change them even you wish. Some 
projects die and same people start a new one, rethinking mistakes made.

> > - core team experience
>
> Not sure this is entirely relevant (imho). Engineers with great
> experience on paper may still make poor decisions and output shoddy
> work. Conversely, a new grad (or weekend hacker) may have a solid
> understanding and output amazing work.

The question is about the practical things you do daily. You might laugh of 
your first project, you continue to move forward and got respect as it is now. 
Imagine you continue to fix your first program up to now, you will probably 
write is somewhat differently. Same applies to frameworks, pursue effectiveness 
for more: users served, application hosted, etc. Some, just can not.

> > - historical path, etc.
>
> What does this mean?

The frameworks are not written in one day, they have historical path with many 
hands on it. This change it, not always right way.

>
 > There is a problem with 3rd party code... it should evolve with 
framework... so good one become a part of it. 3rd party UI things are 
good, until you start `customize` them, patch, workaround, etc. This is 
where pain come from. However, there are exceptions. Can you name few?
>
> [Disclaimer: personal opinion] I couldn't disagree more. A good
> framework provides the glue for various subsystems to work amazingly
> well together. Perhaps this is why I'm drawn to micro-frameworks and
> the likes of Pyramid. No assumptions are made about *how* I'm going to
> use the framework. Modularity is good. Do one thing and do it *very*
> well. Caching? Use beaker. ORM? Use SQLAlchemy.

That glue is usability case: recommendation how to use it with one or the other.

>
 > Let me state this: "wheezy.web let you design web application to 
be able run it at the speed of `hello world`, even database driven one".
>
> This bothers me. It's misleading to newbies and it's just wrong. You
> simply *cannot* have a database driven application run at the exact
> same performance as a "hello world" app.

For you, personally, let me point this again. N.P.

Here is how: use content caching with cache dependency. Read more:
http://packages.python.org/wheezy.http/userguide.html#content-cache
 
Thanks.

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


[off topic], was Re: [on topic] Re: readline trick needed

2012-10-16 Thread Peter Otten
Dwight Hutto wrote:

I knew I'd eventually regret putting "on topic" into the subject...

Well done, Dwight. 

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


Re: overriding equals operation

2012-10-16 Thread Thomas Rachel

Am 16.10.2012 15:51 schrieb Pradipto Banerjee:


I am trying to define class, where if I use a statement a = b, then instead of "a" pointing to the 
same instance as "b", it should point to a copy of "b", but I can't get it right.


This is not possible.



Currently, I have the following:



class myclass(object):


Myclass or MyClass, see http://www.python.org/dev/peps/pep-0008/.


 def __eq__(self, other):
 if instance(other, myclass):
 return self == other.copy()
 return NotImplemented


This redefines the == operator, not the = operator.

It is not possible to redefine =.

One way could be to override assignment of a class attribute. But this 
won't be enough, I think.


Let me explain:

class MyContainer(object):
@property
def content(self):
return self._content
@content.setter
def content(self, new):
self._content = new.copy()

Then you can do:

a = MyClass()
b = MyContainer()
b.content = a
print b.content is a # should print False; untested...

But something like

a = MyClass()
b = a

will always lead to "b is a".


This communication is for informational purposes only. It is not
intended to be, nor should it be construed or used as, financial,
legal, tax or investment advice or an offer to sell, or a
solicitation of any offer to buy, an interest in any fund advised by
Ada Investment Management LP, the Investment advisor.


What?


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


Re: [on topic] Re: readline trick needed

2012-10-16 Thread Dwight Hutto
On Tue, Oct 16, 2012 at 7:27 AM, Steven D'Aprano
 wrote:
> On Tue, 16 Oct 2012 10:30:01 +0200, Peter Otten wrote:
>
>> Steven D'Aprano wrote:
>>
>>> I'm working with the readline module, and I'm trying to set a key
>>> combination to process the current command line by calling a known
>>> function, *and* enter the command line.
>>>
>>> Something along the lines of:
>>>
>>> * execute function spam() in some context where it can access
>>>   the current command line as a string
>>> * enter the command line
>>>

I'm working on the dictionary now,but I came up with this, which uses
a list as the key, and accepts the params to perform the function:

import subprocess as sub
key_list = ['print_something','espeak']

def print_something(params):
print "%s" % (params)

def espeak(params):
sub.call(['espeak','%s' % (params)])

key = raw_input("Please enter key: ")

for line in key_list:
if str(line) == key:
params = raw_input("Enter Params: ")
eval("%s('%s')" % (key,params))


I keep getting the function performed in the dict. I'll figure it out
eventually, I know I've done it before, and it might be a lambda
solution...not sure.

But the above could be refined more, it just uses a list, and key/params.


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


Re: overriding equals operation

2012-10-16 Thread Dave Angel
On 10/16/2012 09:51 AM, Pradipto Banerjee wrote:
> I am trying to define class, where if I use a statement a = b, then instead 
> of "a" pointing to the same instance as "b", it should point to a copy of 
> "b", but I can't get it right.
>
>

The __eq__ method is called for equals comparison, like
  if myinst == otherobj:

There are no hooks for the binding operator (=)




-- 

DaveA

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


Re: Fastest web framework

2012-10-16 Thread Demian Brecht
Let me say right off the bat that I've taken a brief look through the
code and documentation and found that I wouldn't mind trying it out
for personal projects. So, the intention here is not to slag the
framework.

> Performance and effectivity are related metrics. Longer feature list can not 
> explain why it less effective. An answer to effectivity question might be 
> related to:
> - code quality (we have PEP8)

Any static code analysis such as pylint or pyflakes?

> - architectural decisions taken

What (sample of) decisions? How do they differ from other frameworks?
How will they make my life better?

> - core team experience

Not sure this is entirely relevant (imho). Engineers with great
experience on paper may still make poor decisions and output shoddy
work. Conversely, a new grad (or weekend hacker) may have a solid
understanding and output amazing work.

> - historical path, etc.

What does this mean?

> There is a problem with 3rd party code... it should evolve with framework... 
> so good one become a part of it. 3rd party UI things are good, until you 
> start `customize` them, patch, workaround, etc. This is where pain come from. 
> However, there are exceptions. Can you name few?

[Disclaimer: personal opinion] I couldn't disagree more. A good
framework provides the glue for various subsystems to work amazingly
well together. Perhaps this is why I'm drawn to micro-frameworks and
the likes of Pyramid. No assumptions are made about *how* I'm going to
use the framework. Modularity is good. Do one thing and do it *very*
well. Caching? Use beaker. ORM? Use SQLAlchemy.

> Let me state this: "wheezy.web let you design web application to be able run 
> it at the speed of `hello world`, even database driven one".

This bothers me. It's misleading to newbies and it's just wrong. You
simply *cannot* have a database driven application run at the exact
same performance as a "hello world" app.
-- 
http://mail.python.org/mailman/listinfo/python-list


overriding equals operation

2012-10-16 Thread Pradipto Banerjee
I am trying to define class, where if I use a statement a = b, then instead of 
"a" pointing to the same instance as "b", it should point to a copy of "b", but 
I can't get it right.

Currently, I have the following:



class myclass(object):
def __init__(self, name='')
self.name = name

def copy(self):
newvar = myclass(self.name)
return newvar

def __eq__(self, other):
if instance(other, myclass):
return self == other.copy()
return NotImplemented


Now if I try:

>>> a=myclass()
>>> a.name = 'test'
>>> b=a
>>> b.name
'test'
>>> b.name = 'test2'
>>> a.name
'test2'

I wanted b=a to make a new copy of "a", but then when I assigned b.name = 
'test2', even a.name became 'test2'.

How can I rectify my code to make the __eq__() behave like copy()?

Thanks


 This communication is for informational purposes only. It is not intended to 
be, nor should it be construed or used as, financial, legal, tax or investment 
advice or an offer to sell, or a solicitation of any offer to buy, an interest 
in any fund advised by Ada Investment Management LP, the Investment advisor.  
Any offer or solicitation of an investment in any of the Funds may be made only 
by delivery of such Funds confidential offering materials to authorized 
prospective investors.  An investment in any of the Funds is not suitable for 
all investors.  No representation is made that the Funds will or are likely to 
achieve their objectives, or that any investor will or is likely to achieve 
results comparable to those shown, or will make any profit at all or will be 
able to avoid incurring substantial losses.  Performance results are net of 
applicable fees, are unaudited and reflect reinvestment of income and profits.  
Past performance is no guarantee of future results. All financial 
 data and other information are not warranted as to completeness or accuracy 
and are subject to change without notice.

Any comments or statements made herein do not necessarily reflect those of Ada 
Investment Management LP and its affiliates. This transmission may contain 
information that is confidential, legally privileged, and/or exempt from 
disclosure under applicable law. If you are not the intended recipient, you are 
hereby notified that any disclosure, copying, distribution, or use of the 
information contained herein (including any reliance thereon) is strictly 
prohibited. If you received this transmission in error, please immediately 
contact the sender and destroy the material in its entirety, whether in 
electronic or hard copy format.
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2012-10-16 Thread tinnews
Marco Nawijn  wrote:
> On Monday, October 15, 2012 1:33:02 PM UTC+2, (unknown) wrote:
> > I want to fix an error in some code I have installed, however I don't
> > 
> > really want to just bodge it.
> > 
> > 
> > 
> > The function producing the error is:-
> > 
> > 
> > 
> > def get_text(self, idx):   # override !
> > 
> > node = self.items[idx]
> > 
> > 
> > 
> > a= [
> > 
> > ", ".join(node.tags),
> > 
> > node.comment,
> > 
> > node.folderName,
> > 
> > cd2rd(node.date),
> > 
> > node.name,
> > 
> > '[' + self.rating_stars[node.rating] + ']'
> > 
> > ] [self.select]
> > 
> > 
> > 
> > return a
> > 
> > 
> > 
> > 
> > 
> > The error occurs when node[] (or at least its members) turn out to be
> > 
> > empty, you get a Traceback that ends with:-
> > 
> > 
> > 
> >   File "/usr/lib/jbrout/jbrout/listview.py", line 608, in draw_cell 
> > layout.set_text(self.get_text(thumbnail_num))
> > 
> >   File "/usr/lib/jbrout/jbrout.py", line 325, in get_text ", 
> > ".join(node.tags),
> > 
> >   TypeError: sequence item 0: expected string, NoneType found
> > 
> > 
> > 
> > Now its *probably* something higher up the tree causing the problem
> > 
> > (it's only one particular image in 20 thousand or so that breaks
> > 
> > things) but I really want to just get things working.  So, what's the
> > 
> > neatest way to protect the get_text() method from empty data?
> > 
> > 
> > 
> > 
> > 
> > -- 
> > 
> > Chris Green
> Hi,
> 
> Instead of protecting against empty data, you could just catch the exception, 
> issue a warning and return a default "error" node which is valid. So 
> something like (not tested):
> 
> def get_text(self, idx):   # override ! 
> node = self.items[idx] 
> 
> error_a = "A valid, but erroneous representation of a"
> 
> try:
> a= [ 
> ", ".join(node.tags), 
> node.comment, 
> node.folderName, 
> cd2rd(node.date), 
> node.name, 
> '[' + self.rating_stars[node.rating] + ']' 
> ] [self.select] 
> except TypeError:
>   print 'Oops, something went wrong'
>   a = error_a
> # You should always have a valid a here (or another exception has  
> occured)
> return a 

That sounds like a reasonable approach, thank you (and all the other ideas).

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


cx_Oracle clause IN using a variable

2012-10-16 Thread Beppe
Hi all,
I don't know if it is the correct place to set this question, however,
I'm using cx_Oracle to query an Oracle database.
I've a problem to use the IN clause with a variable.
My statement is 

sql = "SELECT field1,field2,field3
FROM my_table
WHERE field_3 IN (:arg_1)"

where arg_1 is retrive by a dictionary
that is build so

 my_dict = {'location':"X",
'oracle_user':'user',
'oracle_password':'pass',
'dsn':'dsn',
'mailto':'some...@somewhere.org',
'codes':"CNI,CNP"}

args = (dict['codes'],)
   
 
con = cx_Oracle.connect(my_dict["oracle_user"],
 my_dict["oracle_password"],
 my_dict["dsn"])
 
cur = con.cursor()
cur.execute(sql,args)
rs =  cur.fetchall()   

but it doesn't work in the sense that doesn't return anything

If i use the statment without variable 

SELECT field1,field2,field3
FROM my_table
WHERE field_3 IN ('CNI','CNP')

the query works

what is wrong?
suggestions?

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


Re: [Neo4j] ANN: python-blueprints, printemps and printemps client

2012-10-16 Thread Javier de la Rosa
Do you need Java [1] to run any of them? There is another alternative
called pyblueprints [2] through REST interface.



[1] http://pyjnius.readthedocs.org/en/latest/installation.html#installation
[2] https://github.com/escalant3/pyblueprints

On Tue, Oct 16, 2012 at 8:43 AM, Amirouche Boubekki
 wrote:
> Héllo,
>
>
> I'm happy to announce about projects related to graph databases, Neo4j and
> OrientDB and Python:
>
> - python-blueprints is a Python bindings of Tinkerpop's Blueprints library
> that allow you to access and query a graph database directly from Python.
> The API is very small you can be ready to take over the world in a matter of
> minutes [documentation][forge]
>
> - printemps-client with its compagnon server printemps allow you to query
> remotly a graph database using only Python functions, if you know
> python-blueprints, you will be up and running in less than 5 minutes!
> checkout the documentation and the code.
>
> The intention of the announcement is (1) I thought others may find it
> useful, and (2) to get feedback. So, please let me know what you think.
>
>
> Amirouche
>
> --
>
>



-- 
Javier de la Rosa
http://versae.es
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using message loop for hotkey capturing

2012-10-16 Thread bagratte
hi all,

i am a complete newbie in windows programming and have come across this 
problem. i wanted a windows systray application which would seat in the 
notification are, would have a tiny popup menu and would also respond to a 
global hotkey. i've assembled something out of the demos in pywin32 which 
actually works except one thing: i don't like it. i am registering the hotkey 
within the window class constructor. something like this:

imports...
...

class MainWindow():
def __init__(self):
...
user32.RegisterHotKey(None, 1, win32con.MOD_CONTROL, ord('A'))

message_map = {win32con.WM_DESTROY: self.OnDestroy,
   win32con.WM_COMMAND: self.OnCommand,
   win32con.WM_USER+20: self.OnTaskbarNotify,
   win32con.WM_HOTKEY: self.OnHotKey}
...

def OnCommand(self, hwnd, msg, wparam, lparam):
print "OnCommand"

def OnHotKey(self):
print "OnHotkey"

def OnDestroy(self, hwnd, msg, wparam, lparam):
user32.UnregisterHotKey(None, 1)
...

...

def myLoop():
msg = wintypes.MSG()
while user32.GetMessageA(byref(msg), None, 0, 0) != 0:
if msg.message == win32con.WM_HOTKEY:
w.OnHotKey()
user32.TranslateMessage(byref(msg))
user32.DispatchMessageA(byref(msg))

w = MainWindow()
#PumpMessages()
myLoop()



now, if i use myLoop(), which is ripped from tim golden's "home-grown-loop", 
everything works. however, if i use PumpMessages(), the program won't respond 
to WM_HOTKEY, and it won't respond to WM_COMMAND (it will respond to 
WM_USER+20).
i was wondering if what i've done is not a ridiculously wrong way to do it. in 
other words, is there any way to make the window respond to WM_HOTKEY thus 
working with PumpMessages()?

i thank you all for your patience (this is my first ever windows programming 
experience).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [on topic] Re: readline trick needed

2012-10-16 Thread Steven D'Aprano
On Tue, 16 Oct 2012 13:20:24 +0100, Robert Kern wrote:

> On 10/16/12 12:27 PM, Steven D'Aprano wrote:

>> Well, I was hoping for a pure Python solution, rather than having to
>> troll through who knows how many thousands of lines of code in a
>> language I can barely read.
> 
> Are you confusing IPython, the pure Python REPL for CPython, 

IPython is pure Python?

Well, you learn something new everyday. Or at least I do.

I guess that means that I can look forward to trolling through 250 or so 
Python modules instead of C code :)


Thanks to everyone who replied.


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


ANN: python-blueprints, printemps and printemps client

2012-10-16 Thread Amirouche Boubekki
Héllo,


I'm happy to announce about projects related to graph databases, Neo4j and
OrientDB and Python:

- python-blueprints is a Python bindings of Tinkerpop's
Blueprintslibrary that
allow you to access and query a graph database directly from
Python. The API is very small you can be ready to take over the world in a
matter of minutes
[documentation
][forge ]

- printemps-client with its compagnon server printemps allow you to query
remotly a graph database using only Python functions, if you know
python-blueprints, you will be up and running in less than 5 minutes!
checkout the 
documentationand
the
code .

The intention of the announcement is (1) I thought others may find it useful,
and (2) to get feedback. So, please let me know what you think.


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


Re: Accessing variables in __init__.py

2012-10-16 Thread Gaudha
On Tuesday, October 16, 2012 3:41:55 PM UTC+5:30, Marco Nawijn wrote:
> On Tuesday, October 16, 2012 10:48:17 AM UTC+2, Gaudha wrote:
> 
> > my_package/
> 
> > 
> 
> >   __init__.py
> 
> > 
> 
> >   my_module1.py
> 
> > 
> 
> >   my_module2.py
> 
> > 
> 
> >   variables.py
> 
> > 
> 
> > 
> 
> > 
> 
> > I want to define common variables in __init__.py and use the namespace in 
> > my_module1.py or my_module2.py. Defining it is not a problem. How can call 
> > it from my modules?
> 
> > 
> 
> > 
> 
> > 
> 
> > If I define them in a module (say, variables.py), I can call them by 
> > importing variables.py in other modules. How can it be done if I define it 
> > in __init__.py?
> 
> > 
> 
> > 
> 
> > 
> 
> > It may be a silly query as I am newbie in Python. But, I would be grateful 
> > to get help.
> 
> 
> 
> Hi,
> 
> 
> 
> If you store the variables in __init__.py, you can import them from the 
> package. So in your case suppose __init__.py contains:
> 
> a = 10
> 
> b = {1 :"Hello", 2: "World" }
> 
> 
> 
> Than if you import my_package, you can access the variables as follows 
> (interactive IPython session):
> 
> 
> 
> In [1]: import my_package
> 
> 
> 
> In [2]: my_pack
> 
> my_package   my_package/  
> 
> 
> 
> In [2]: my_package.
> 
> my_package.a  my_package.b  
> 
> 
> 
> In [2]: my_package.a
> 
> Out[2]: 10
> 
> 
> 
> In [3]: my_package.b
> 
> Out[3]: {1: 'Hello', 2: 'World'}
> 
> 
> 
> In [4]:

Yea. I got it. It was a new information for me. A module in a package can 
import its own mother package to call the variables in __init__.

Is it funny or an extraordinary feature? Anyway. I felt it as something weird. 
Guido should have done it something like how 'self' behaves in classes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [on topic] Re: readline trick needed

2012-10-16 Thread Robert Kern

On 10/16/12 12:27 PM, Steven D'Aprano wrote:

On Tue, 16 Oct 2012 10:30:01 +0200, Peter Otten wrote:


Steven D'Aprano wrote:


I'm working with the readline module, and I'm trying to set a key
combination to process the current command line by calling a known
function, *and* enter the command line.

Something along the lines of:

* execute function spam() in some context where it can access
   the current command line as a string
* enter the command line

Function spam() may or may not modify the command line.



(P.S. I'm aware of IPython, I want to get this working in the standard
CPython interpreter.)


If IPython does what you want why don't you have a look at the source?


Well, I was hoping for a pure Python solution, rather than having to
troll through who knows how many thousands of lines of code in a language
I can barely read.


Are you confusing IPython, the pure Python REPL for CPython, for IronPython, the 
C# implementation of Python?


  https://github.com/ipython/ipython

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: Providing a Python wrapper to a C++ type.

2012-10-16 Thread Stefan Behnel
Marco Nawijn, 16.10.2012 13:46:
> I never worked with Cython (but I know it is very powerful and
> interesting) but in my mind there are slight differences in usage
> scenario between e.g. Boost Python and Cython. For me the idea of Cython
> is that your main code is in Python

Normally, yes. You can embed Cython code in C++ just like any other C code
(with the caveat of needing to make sure the Python runtime is properly set
up), but that certainly isn't the most popular use case.


> but you want to improve the
> performance of specific parts of the code. In that case, Cython is the
> way to go. In case of Boost Python, the scenario for me is that you have
> a main program/library in C++, but you want to be able use the
> functionality from Python.

That's really just a slight difference. What kind of code initially started
up an application is quite irrelevant once it has been running for a while.
The distinction between embedding and extending, as the Python docs put it,
is actually quite fuzzy when it comes to the actual code interaction.

Note also that this isn't the use case here, the OP asked for wrapping a
C++ type for use in Python.

Stefan

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


Re: Python on Windows

2012-10-16 Thread Dwight Hutto
On Tue, Oct 16, 2012 at 7:35 AM, Marco Nawijn  wrote:
> On Tuesday, October 16, 2012 1:29:23 PM UTC+2, graham wrote:
>> Downloaded and installed Python 2.7.3 for windows (an XP machine).
>>
>>
>>
>> Entered the Python interactive interpreter/command line and typed the
>>
>> following:
>>
>>
>>
>>   >>>import feedparser
>>
>>
>>
>> and I get the error message "No module named feedparser".
>>
>>

Did you install it into the site-packages directory? Or did you cd to
the directory it's in, and launch, or place it into the directory
you're trying to launch it from?
>>


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


RE: Fastest web framework

2012-10-16 Thread Andriy Kornatskyy

Alex,

Thank you, see my answers inline to your comments:

> Performance speed is possibly the least interesting aspect of web
> frameworks;

Performance and effectivity are related metrics. Longer feature list can not 
explain why it less effective. An answer to effectivity question might be 
related to:
- code quality (we have PEP8)
- architectural decisions taken
- core team experience
- historical path, etc.

> ease of use & readily re-usable 3rd party code figures
> much higher, IMO.

I think these are very valid requirements for the modern web framework. I 
believe all web frameworks are easy to use (... some too seriously take this?), 
of cause readability/flexibility counts.

There is a problem with 3rd party code... it should evolve with framework... so 
good one become a part of it. 3rd party UI things are good, until you start 
`customize` them, patch, workaround, etc. This is where pain come from. 
However, there are exceptions. Can you name few?

> Rather than constantly hammer on about performance,
> maybe you could take the time to explain any other advantages your
> framework provides.

Let me state this: "wheezy.web let you design web application to be able run it 
at the speed of `hello world`, even database driven one".

Here is how: use content caching with cache dependency. Read more:
http://packages.python.org/wheezy.http/userguide.html#content-cache

Invest 30 minutes to understand it:
http://packages.python.org/wheezy.web/tutorial.html

All web frameworks are good, some better. It is important what you see as an 
advantage...

Thanks.

Andriy Kornatskyy



> Date: Mon, 15 Oct 2012 18:26:16 -0700
> Subject: Re: Fastest web framework
> From: wuwe...@gmail.com
> To: python-list@python.org
>
> On Oct 15, 11:40 pm, Andriy Kornatskyy 
> wrote:
>> Comments or suggestions are welcome.
>
> Performance speed is possibly the least interesting aspect of web
> frameworks; ease of use & readily re-usable 3rd party code figures
> much higher, IMO. Rather than constantly hammer on about performance,
> maybe you could take the time to explain any other advantages your
> framework provides.
> --
> http://mail.python.org/mailman/listinfo/python-list
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Providing a Python wrapper to a C++ type.

2012-10-16 Thread Marco Nawijn
On Tuesday, October 16, 2012 1:39:44 PM UTC+2, Stefan Behnel wrote:
> Marco Nawijn, 16.10.2012 12:17:
> 
> > On Tuesday, October 16, 2012 10:11:52 AM UTC+2, aaron.l...@gmail.com wrote:
> 
> >> I have a C++ module where I have a defined, working type. How would I
> 
> >> make a wrapper for this type to be able to be used in Python? I am
> 
> >> familiar(-ish) with the C-API for functions but I can't see concretely how
> 
> >> one would include an interface to a type.
> 
> >>
> 
> >> Is it this? http://docs.python.org/release/2.7.3/extending/newtypes.html
> 
> > 
> 
> > There are a few ways of doing this. At least three come to my mind:
> 
> > 1. Wrap the C++ type yourself by using handcrafted code implemented with 
> > the Python C API
> 
> > 2. Use SWIG to wrap the C++ code and (semi) automatically create the 
> > wrapper (http://www.swig.org/)
> 
> > 3. Use BOOST Python to wrap the C++ code 
> > (http://www.boost.org/doc/libs/1_51_0/libs/python/doc/index.html)
> 
> > 
> 
> > I would highly discourage (1) unless you are very brave and curious. 
> > Ofcourse it is a nice excercise, but if you want something to work quickly 
> > I would recommend to use either (2) or (3).
> 
> > 
> 
> > I have used both SWIG and BOOST Python and either of them worked pretty 
> > well for me. In the end I selected BOOST Python, because I was only 
> > interested in the Python wrapping (SWIG could generate many other wrappers 
> > as well).
> 
> 
> 
> There's also Cython, which provides a very flexible way (unlike SWIG) of
> 
> doing these things easily (unlike C++ with Boost).
> 
> 
> 
> http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html
> 
> 
> 
> I agree with discouraging 1) in specific.
> 
> 
> 
> Stefan

Hi Stefan,

I never worked with Cython (but I know it is very powerful and interesting) but 
in my mind there are slight differences in usage scenario between e.g. Boost 
Python and Cython. For me the idea of Cython is that your main code is in 
Python, but you want to improve the performance of specific parts of the code. 
In that case, Cython is the way to go. In case of Boost Python, the scenario 
for me is that you have a main program/library in C++, but you want to be able 
use the functionality from Python. 

Do you agree with this view?

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


Re: Python on Windows

2012-10-16 Thread Joel Goldstick
On Tue, Oct 16, 2012 at 7:29 AM, graham  wrote:
>
> Downloaded and installed Python 2.7.3 for windows (an XP machine).
>
> Entered the Python interactive interpreter/command line and typed the
> following:
>
> >>>import feedparser
>
> and I get the error message "No module named feedparser".
>
> There is a feedparser.py file lurking around - so I suppose Python cannot
> find it.
>
> Anyone: What to do?
>
>
I'm guessing your python path is not set up.  Look here:
http://docs.python.org/using/windows.html

or google windows xp setting python path


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



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


Re: Python on Windows

2012-10-16 Thread Marco Nawijn
On Tuesday, October 16, 2012 1:29:23 PM UTC+2, graham wrote:
> Downloaded and installed Python 2.7.3 for windows (an XP machine).
> 
> 
> 
> Entered the Python interactive interpreter/command line and typed the 
> 
> following:
>
> 
> 
>   >>>import feedparser
> 
> 
> 
> and I get the error message "No module named feedparser".
> 
> 
> 
> There is a feedparser.py file lurking around - so I suppose Python 
> 
> cannot find it.
> 
> 
> 
> Anyone: What to do?
> 
> 
> 
> 
> 
> 
> 
> GC
Hi,

feedparser.py is not a Python standard library. So, if it feedparser is located 
in a non-standard folder you have at least the following two options:
1. Update the PYTHONPATH environment variable such that it includes the path 
the installation location of feedparser.py

2. Add the path to feedparser.py directly in the script that uses it. Something 
like the following:
import sys
sys.path.append("path to feedparser.py")

import feedparser

Regards,

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


Re: Providing a Python wrapper to a C++ type.

2012-10-16 Thread Stefan Behnel
Marco Nawijn, 16.10.2012 12:17:
> On Tuesday, October 16, 2012 10:11:52 AM UTC+2, aaron.l...@gmail.com wrote:
>> I have a C++ module where I have a defined, working type. How would I
>> make a wrapper for this type to be able to be used in Python? I am
>> familiar(-ish) with the C-API for functions but I can't see concretely how
>> one would include an interface to a type.
>>
>> Is it this? http://docs.python.org/release/2.7.3/extending/newtypes.html
> 
> There are a few ways of doing this. At least three come to my mind:
> 1. Wrap the C++ type yourself by using handcrafted code implemented with the 
> Python C API
> 2. Use SWIG to wrap the C++ code and (semi) automatically create the wrapper 
> (http://www.swig.org/)
> 3. Use BOOST Python to wrap the C++ code 
> (http://www.boost.org/doc/libs/1_51_0/libs/python/doc/index.html)
> 
> I would highly discourage (1) unless you are very brave and curious. Ofcourse 
> it is a nice excercise, but if you want something to work quickly I would 
> recommend to use either (2) or (3).
> 
> I have used both SWIG and BOOST Python and either of them worked pretty well 
> for me. In the end I selected BOOST Python, because I was only interested in 
> the Python wrapping (SWIG could generate many other wrappers as well).

There's also Cython, which provides a very flexible way (unlike SWIG) of
doing these things easily (unlike C++ with Boost).

http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html

I agree with discouraging 1) in specific.

Stefan


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


Python on Windows

2012-10-16 Thread graham


Downloaded and installed Python 2.7.3 for windows (an XP machine).

Entered the Python interactive interpreter/command line and typed the 
following:


>>>import feedparser

and I get the error message "No module named feedparser".

There is a feedparser.py file lurking around - so I suppose Python 
cannot find it.


Anyone: What to do?



GC

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


Re: [on topic] Re: readline trick needed

2012-10-16 Thread Steven D'Aprano
On Tue, 16 Oct 2012 10:30:01 +0200, Peter Otten wrote:

> Steven D'Aprano wrote:
> 
>> I'm working with the readline module, and I'm trying to set a key
>> combination to process the current command line by calling a known
>> function, *and* enter the command line.
>> 
>> Something along the lines of:
>> 
>> * execute function spam() in some context where it can access
>>   the current command line as a string
>> * enter the command line
>> 
>> Function spam() may or may not modify the command line.
> 
>> (P.S. I'm aware of IPython, I want to get this working in the standard
>> CPython interpreter.)
> 
> If IPython does what you want why don't you have a look at the source?

Well, I was hoping for a pure Python solution, rather than having to 
troll through who knows how many thousands of lines of code in a language 
I can barely read.


> Anyway, here's what I came up with (no warranties as it was all
> trial-and- error):
> 
> $ cat readline_callback.py
> import ctypes

Ah, ctypes.

Well, I guess I have some interesting study ahead of me, to make head or 
tail of your solution. Thank you!



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


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

2012-10-16 Thread Marco Nawijn
On Tuesday, October 16, 2012 12:43:09 AM UTC+2, someone wrote:
> On 10/15/2012 11:26 PM, MRAB wrote:
> 
> > On 2012-10-15 22:09, someone wrote:
> 
> >>
> 
> >> See this:
> 
> >>
> 
> >> ==
> 
> >> In [5]: Dx = numpy.matrix('1 0 0; 0 0.5 -0.5; 0 -0.5 1.5')
> 
> >>
> 
> >> In [6]: Dx
> 
> >> Out[6]:
> 
> >> matrix([[ 1. ,  0. ,  0. ],
> 
> >>   [ 0. ,  0.5, -0.5],
> 
> >>   [ 0. , -0.5,  1.5]])
> 
> >> ==
> 
> >>
> 
> >>
> 
> >>
> 
> >> Ok... So now test = 33 and instead of the value 1.5 I want to use the
> 
> >> value of "test" and put it directly into the matrix (or array):
> 
> >>
> 
> >> ==
> 
> >> In [7]: test=33
> 
> >>
> 
> >> In [8]: Dx = numpy.matrix('1 0 0; 0 0.5 -0.5; 0 -0.5 test')
> 
> >> ---
> 
> >>
> 
> >> NameError Traceback (most recent call
> 
> >> last)
> 
> >> /home/user/something/ in ()
> 
> >> > 1 Dx = numpy.matrix('1 0 0; 0 0.5 -0.5; 0 -0.5 test')
> 
> >>
> 
> >> /usr/lib/python2.7/dist-packages/numpy/matrixlib/defmatrix.pyc in
> 
> >> __new__(subtype, data, dtype, copy)
> 
> >>   252
> 
> >>   253 if isinstance(data, str):
> 
> >> --> 254 data = _convert_from_string(data)
> 
> >>   255
> 
> >>   256 # now convert data to an array
> 
> >> .. etc...
> 
> >> ==
> 
> >>
> 
> >>
> 
> >>
> 
> >> So obviously it doesn't understand that I want this:
> 
> >>
> 
> >> ==
> 
> >> In [21]: Dx[2,2]=test
> 
> >>
> 
> >> In [22]: Dx
> 
> >> Out[22]:
> 
> >> matrix([[  1. ,   0. ,   0. ],
> 
> >>   [  0. ,  33. ,  -0.5],
> 
> >>   [  0. ,  -0.5,  33. ]])
> 
> >> ==
> 
> >>
> 
> >> Without having to manually change all the individual places using my
> 
> >> variables (test is actually many variables, not just one but I think you
> 
> >> should understand the problem now).
> 
> >>
> 
> >>
> 
> >> How to initialize my array directly using variables ?
> 
> >>
> 
> >> It could also be that I wanted:
> 
> >>
> 
> >> test11 = 1
> 
> >> test12 = 1.5
> 
> >> test13 = 2
> 
> >> test21 = 0
> 
> >> test22 = 5
> 
> >>
> 
> >> Dx = numpy.matrix('test11 test12 test13; test21 test22 -0.5; 0 -0.5 1.5')
> 
> >>
> 
> >> Etc... for many variables...
> 
> >>
> 
> >> Appreciate ANY help, thank you very much!
> 
> >>
> 
> > What it prints should give you a hint:
> 
> >
> 
> >  >>> Dx = numpy.matrix([[test11, test12, test13], [test21, test22,
> 
> > -0.5], [0, -0.5, 1.5]])
> 
> >  >>> Dx
> 
> > matrix([[ 1. ,  1.5,  2. ],
> 
> >  [ 0. ,  5. , -0.5],
> 
> >  [ 0. , -0.5,  1.5]])
> 
> 
> 
> Uh, great - thank you very much!
> 
> 
> 
> As you maybe see, I'm only a python newbie so I'm not so good at 
> 
> understanding the error messages and reading the source code yet.
> 
> 
> 
> Thank you very much for the solution to the problem! It's highly 
> 
> appreciated. Thanks.

Hi,

Also note that you don't need to initialize the array with a string. You could 
directly do it like this:

>>> a = numpy.array(((1,2,3), (2,3,4), (4,5,6)))

Other things that might be interesting for you are:

# List comprehension (standard python) to convert strings to floats
>>> vals = [ float(s) for s in "1.0 2.3 1.2".split() ]
produces [1.0, 2.3, 1.2]
>>> vals = [ float(s) for s in ("1.0", "2.3", "1.2") ]
produces again [1.0, 2.3, 1.2]

Also lookup the documentation for numpy.reshape. With this you could provide a 
single list of for example 9 numbers and reshape it into a 3x3 array.

Python and Numpy are so cool!!

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


Re: Which book is the best?

2012-10-16 Thread Marco Nawijn
On Tuesday, October 16, 2012 6:41:29 AM UTC+2, David Hutto wrote:
> On Tue, Oct 16, 2012 at 12:27 AM, 老爷  wrote:
> 
> > I have strong c++ development experience.  But now I want to study the
> 
> > python to do some windows setting task, such as editing file, changing the
> 
> > system setting, doing some network processing.  Please help me which book is
> 
> > the best?
> 
> >
> 
> >
> 
> Definitely command line apps/command line usage.
> 
> 
> 
>  I could recommend google searches, but use the calls to the OS, and
> 
> you can accomplish a good bit of things.
> 
> 
> 
> 
> 
> -- 
> 
> Best Regards,
> 
> David Hutto
> 
> CEO: http://www.hitwebdevelopment.com

Hi,

Although I agree with the fact the working in the interactive interpreter (may 
I recommend IPython for this) is definitely an efficient way of exploring the 
Python world, I also liked alot the Python Essential Reference (4th edition). 
Since you already understand how to program, the Python essential reference 
quickly guides you through Python language and the standard library.

Regards,

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


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

2012-10-16 Thread Marco Nawijn
On Tuesday, October 16, 2012 5:43:28 AM UTC+2, J wrote:
> Hi...
> 
> 
> 
> I have a bit of code that does the following:
> 
> 
> 
> uses the syslog module to inject a LOG_INFO message into the syslog on
> 
> my linux machine
> 
> runs a suspend/resume cycle
> 
> uses the syslog module to inkect a LOG_INFO message marking the end of test.
> 
> 
> 
> Then I parse everything between the start and stop markers for certain
> 
> items that the Linux kernel logs during a suspend and resume cycle.
> 
> 
> 
> But my  "resume complete" timing is not as accurate as it could be.
> 
> The problem with doing it this way is that while I can find definite
> 
> kernel messages that mark various points in the suspend/resume cycle,
> 
> the final message when the kernel is done resuming is NOT the point I
> 
> actually want to mark.
> 
> 
> 
> Instead, the end point I want is the time of the ending marker itself,
> 
> as this happens after certain other things are done such as resumption
> 
> of networking services.
> 
> 
> 
> Here's the problem.  I can't just use syslog timestamps.  The reason
> 
> is that the syslog timestamps are only indicative of when messages are
> 
> written to syslog via syslogd.  The kernel timestamps are different.
> 
> For example, the following bits of log are taken from the time the
> 
> test starts until the end of the "going to sleep" kernel messages.
> 
> First, note that there's a 5 second difference between the START
> 
> marker and the first kernel message.  Next, look at the kernel
> 
> timestamps.  The total real time to suspend starts at 421320.380947
> 
> and ends at 421322.386355, around 2 seconds later, where the log
> 
> messages themselves all state that the events occurred at the same
> 
> time.
> 
> 
> 
> Oct 15 10:24:19 klaatu sleep_test: ---SLEEP TEST START 1350296656---
> 
> Oct 15 10:25:24 klaatu kernel: [421320.380947] PM: Syncing filesystems ... 
> done.
> 
> Oct 15 10:25:24 klaatu kernel: [421320.391282] PM: Preparing system
> 
> for mem sleep
> 
> [SNIP]
> 
> Oct 15 10:25:24 klaatu kernel: [421322.282943] Broke affinity for irq 23
> 
> Oct 15 10:25:24 klaatu kernel: [421322.386355] CPU 7 is now offline
> 
> 
> 
> So, what I REALLY want is to inject my start/stop markers into klogd
> 
> rather than syslogd.  This will, I hope, give my markers kernel
> 
> timestamps rather than syslog timestamps which are not as accurate.
> 
> 
> 
> So does anyone know of a way to do this?  Unfortunately, I've tried
> 
> some searching but google doesn't like the term klog, and most of the
> 
> hits involved injecting code or other things that are not related at
> 
> all.
> 
> 
> 
> Or, if there's a better way to get accurate timestamps, what would that be?

Hi,

I cannot be of too much help here, but is there a userspace/kernel C-interface 
that could be used. If so, you might be able to use the Python ctypes module to 
create messages at the correct moments

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


Re: Providing a Python wrapper to a C++ type.

2012-10-16 Thread Marco Nawijn
On Tuesday, October 16, 2012 10:11:52 AM UTC+2, aaron.l...@gmail.com wrote:
> Hi,
> 
> 
> 
> I have a C++ module where I have a defined, working type. How would I make a 
> wrapper for this type to be able to be used in Python? I am familiar(-ish) 
> with the C-API for functions but I can't see concretely how one would include 
> an interface to a type.
> 
> 
> 
> Is it this? http://docs.python.org/release/2.7.3/extending/newtypes.html
> 
> 
> 
> Regards,
> 
> Aaron

Hi Aaron,

There are a few ways of doing this. At least three come to my mind:
1. Wrap the C++ type yourself by using handcrafted code implemented with the 
Python C API
2. Use SWIG to wrap the C++ code and (semi) automatically create the wrapper 
(http://www.swig.org/)
3. Use BOOST Python to wrap the C++ code 
(http://www.boost.org/doc/libs/1_51_0/libs/python/doc/index.html)

I would highly discourage (1) unless you are very brave and curious. Ofcourse 
it is a nice excercise, but if you want something to work quickly I would 
recommend to use either (2) or (3).

I have used both SWIG and BOOST Python and either of them worked pretty well 
for me. In the end I selected BOOST Python, because I was only interested in 
the Python wrapping (SWIG could generate many other wrappers as well).

Regards,

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


Re: [on topic] Re: readline trick needed

2012-10-16 Thread Peter Otten
Ned Deily wrote:

> In article , Peter Otten <__pete...@web.de>
> wrote:
>> Steven D'Aprano wrote:
>> > I'm working with the readline module, and I'm trying to set a key
>> > combination to process the current command line by calling a known
>> > function, *and* enter the command line.
> [...]
>> Anyway, here's what I came up with (no warranties as it was all
>> trial-and- error):
> [...]
> 
> Keep in mind that the Python readline module may be linked to either the
> GPL-licensed GNU readline or the BSD-licensed editline (libedit) library
> (the default on newer OS X systems and probably on *BSD systems) and
> they have different command strings.  Note the warning here:
> 
> http://docs.python.org/py3k/library/readline.html

I think you are a Mac user. If so, can the snippet I posted be generalised 
to work with libedit?
 
> Or it may not be linked with either.

OK, change "no warranties" to "absolutely no warranties" ;)


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


Re: Accessing variables in __init__.py

2012-10-16 Thread Marco Nawijn
On Tuesday, October 16, 2012 10:48:17 AM UTC+2, Gaudha wrote:
> my_package/
> 
>   __init__.py
> 
>   my_module1.py
> 
>   my_module2.py
> 
>   variables.py
> 
> 
> 
> I want to define common variables in __init__.py and use the namespace in 
> my_module1.py or my_module2.py. Defining it is not a problem. How can call it 
> from my modules?
> 
> 
> 
> If I define them in a module (say, variables.py), I can call them by 
> importing variables.py in other modules. How can it be done if I define it in 
> __init__.py?
> 
> 
> 
> It may be a silly query as I am newbie in Python. But, I would be grateful to 
> get help.

Hi,

If you store the variables in __init__.py, you can import them from the 
package. So in your case suppose __init__.py contains:
a = 10
b = {1 :"Hello", 2: "World" }

Than if you import my_package, you can access the variables as follows 
(interactive IPython session):

In [1]: import my_package

In [2]: my_pack
my_package   my_package/  

In [2]: my_package.
my_package.a  my_package.b  

In [2]: my_package.a
Out[2]: 10

In [3]: my_package.b
Out[3]: {1: 'Hello', 2: 'World'}

In [4]: 

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


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

2012-10-16 Thread Marco Nawijn
On Monday, October 15, 2012 1:33:02 PM UTC+2, (unknown) wrote:
> I want to fix an error in some code I have installed, however I don't
> 
> really want to just bodge it.
> 
> 
> 
> The function producing the error is:-
> 
> 
> 
> def get_text(self, idx):   # override !
> 
> node = self.items[idx]
> 
> 
> 
> a= [
> 
> ", ".join(node.tags),
> 
> node.comment,
> 
> node.folderName,
> 
> cd2rd(node.date),
> 
> node.name,
> 
> '[' + self.rating_stars[node.rating] + ']'
> 
> ] [self.select]
> 
> 
> 
> return a
> 
> 
> 
> 
> 
> The error occurs when node[] (or at least its members) turn out to be
> 
> empty, you get a Traceback that ends with:-
> 
> 
> 
>   File "/usr/lib/jbrout/jbrout/listview.py", line 608, in draw_cell 
> layout.set_text(self.get_text(thumbnail_num))
> 
>   File "/usr/lib/jbrout/jbrout.py", line 325, in get_text ", 
> ".join(node.tags),
> 
>   TypeError: sequence item 0: expected string, NoneType found
> 
> 
> 
> Now its *probably* something higher up the tree causing the problem
> 
> (it's only one particular image in 20 thousand or so that breaks
> 
> things) but I really want to just get things working.  So, what's the
> 
> neatest way to protect the get_text() method from empty data?
> 
> 
> 
> 
> 
> -- 
> 
> Chris Green
Hi,

Instead of protecting against empty data, you could just catch the exception, 
issue a warning and return a default "error" node which is valid. So something 
like (not tested):

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

error_a = "A valid, but erroneous representation of a"

try:
a= [ 
", ".join(node.tags), 
node.comment, 
node.folderName, 
cd2rd(node.date), 
node.name, 
'[' + self.rating_stars[node.rating] + ']' 
] [self.select] 
except TypeError:
  print 'Oops, something went wrong'
  a = error_a
# You should always have a valid a here (or another exception has  
occured)
return a 
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Fastest web framework

2012-10-16 Thread Andriy Kornatskyy

Per community request I have updated benchmarks for web2py 2.1.1 release (the 
newer version performs 26% better; no error while running on pypy):

Here are updated posts, just in case:

http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html
http://mindref.blogspot.com/2012/10/python-web-routing-benchmark.html

Thanks.

Andriy



> From: andriy.kornats...@live.com
> To: python-list@python.org
> Subject: RE: Fastest web framework
> Date: Tue, 9 Oct 2012 16:44:19 +0300
>
>
> How fast python web framework process routing (URL dispatch)?
>
> Here is a benchmark for various web frameworks (bottle, django, flask, 
> pyramid, tornado and wheezy.web) running the following routing: static, 
> dynamic, SEO and missing... with a trivial 'hello world' application (all 
> routes are pointing to the same handler).
>
> http://mindref.blogspot.com/2012/10/python-web-routing-benchmark.html
>
> Benchmark is executed in isolated environment using CPython 2.7.
>
> Comments or suggestions are welcome.
>
> Thanks.
>
> Andriy Kornatskyy
>
> > From: andriy.kornats...@live.com
> > To: python-list@python.org
> > Subject: Fastest web framework
> > Date: Sun, 23 Sep 2012 12:19:16 +0300
> >
> >
> > I have run recently a benchmark of a trivial 'hello world' application for 
> > various python web frameworks (bottle, django, flask, pyramid, web.py, 
> > wheezy.web) hosted in uWSGI/cpython2.7 and gunicorn/pypy1.9... you might 
> > find it interesting:
> >
> > http://mindref.blogspot.com/2012/09/python-fastest-web-framework.html
> >
> > Comments or suggestions are welcome.
> >
> > Thanks.
> >
> > Andriy Kornatskyy
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
>
> --
> http://mail.python.org/mailman/listinfo/python-list
  
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2012-10-16 Thread Jean-Michel Pichavant


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

Hi Chris,

Usually, you want to keep your variable types consistent. For instance, if 
node.tags is supposed to be a string, then make it so that it is always a 
string.
However NoneType may be one inconsistent type that is acceptable for any 
variable. It depends on the situation, and your personal preferences.

To go back to your example, None may have a different meaning that an empty 
string. Here's a way to redefine locally a None object into an empty string:

", ".join(node.tags or '')

if node itself can be None, here's a way to protect against None attribute 
access:

", ".join(node and node.tags)

you can combine the 2 methods:

", ".join((node and node.tags) or '')


This method uses the fact that:
A and B returns B if bool(A) and bool(B) are True, returns the first non True 
between A and B.
A or B returns B if bool(A) is False, returns A if bool(A) is True.

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


Immediate Hire Hyderabad: Requirement for Python Developer/ Lead with 4-8 yrs.Email me if you are interested at srav...@galloptech.com

2012-10-16 Thread Satyavolu Sravani
•  Development of RESTful web services using Python/WSGI.
•  Implement and maintain applications using Python and Oracle.
•  Create automated test coverage and continuous integration for new & existing 
code.
•  Create/use tools to load and update statistical & editorial content in 
Oracle database.
•  Create integration between secure file transfer system, data integration 
batch jobs, and operational RDBMS.
•  Experience using git
•  Manage codebase, builds & branches using git / jenkins / bcfg2. 
•  Experience working with XML
•  Experience with Python web servers 
-- 
http://mail.python.org/mailman/listinfo/python-list


Immediate need for Python Developers (Django,mysql, jquery) Work locations Hyderabad/Mumbia, exp: 4-8yrs, please share resumes to ayesh...@galloptech.com.

2012-10-16 Thread Ayesha D.

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


  1   2   >