Re: A problem with classes - derived type

2016-05-09 Thread Peter Otten
Paulo da Silva wrote:

> Hi!
> 
> Suppose I have a class A whose implementation I don't know about.
> That class A has a method f that returns a A object.
> 
> class A:
> ...
> def f(self, <...>):
> ...
> 
> Now I want to write B derived from A with method f1. I want f1 to return
> a B object:
> 
> class B(A):
> ...
> def f1(self, <...>):
> ...
> res=f(<...>)
> 
> How do I return res as a B object?

In the general case you need enough knowledge about A to create a B instance 
from an A instance:

class B(A):
@classmethod
def from_A(cls, a):
b = cls(...) # or B(...)
return b
def f1(self, ...):
return self.from_A(self.f(...))

If the internal state doesn't change between A and B, and A is written in 
Python changing the class of the A instance to B

class B(A):
def f1(...):
a = self.f(...)
a.__class__ = B
return a

may also work.

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


Re: What's wrong with this concatenation statement?

2016-05-09 Thread Steven D'Aprano
On Monday 09 May 2016 09:10, DFS wrote:

> sSQL =  "line 1\n"
> sSQL += "line 2\n"
> sSQL += "line 3"

Pointlessly provocative subject line edited.

Since all three lines are constants know by the programmer at the time the 
source code is written, it should be written as:


sSQL = """line 1
line 2
line 3"""

Or if you prefer:

sSQL = "line 1\nline 2\nline 3"


Or even:

sSQL = ("line 1\n"
"line 2\n"
"line 3")

taking advantage of Python's compile-time implicit concatenation of string 
constants.



-- 
Steve

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


Re: Python PygLatin

2016-05-09 Thread alister
On Sun, 08 May 2016 11:01:58 -0700, Christopher Reimer wrote:

> On 5/8/2016 10:53 AM, alister wrote:
>> On Mon, 09 May 2016 03:12:14 +1000, Steven D'Aprano wrote:
>>
>>> On Sun, 8 May 2016 08:21 pm, Cai Gengyang wrote:
>>>
 If one looks at the Forbes List, you will see that there are 4
 programmers amongst the top ten richest people in the world (Bill
 Gates, Mark Zuckerberg, Larry Ellison and Jeff Bezos) , a very large
 percentage. Science and Technology is in a sense the most egalitarian
 field in the world, because it involves using your brains and
 creativity. You don't need to have a father who is a director at
 Goldman Sachs or a mother who is the admissions officer at Harvard to
 succeed in this line.
>>> Bill Gates III's father was a prominent lawyer, his mother was on the
>>> board of directors for First Interstate BancSystem and United Way, and
>>> one of his grandfathers was a national bank president. Gates himself
>>> went to Harvard.
>>>
>>> Zuckerberg's paternal grandparents were successful middle class,
>>> described as  being the first on the block to own a colour TV. (This
>>> was back in the days when colour TVs were an expensive toy that few
>>> could afford.) His parents were also very successful professionals: a
>>> dentist and a psychiatrist. And he too went to Harvard. Despite the
>>> jeans and tee-shirts Zuckerberg is known for wearing, he's firmly from
>>> the professional/upper class.
>>>
>>> Bezos comes from a family of land-holders from Texas. His grandfather
>>> was regional director of the U.S. Atomic Energy Commission, and was
>>> financially successful enough to retire at an early age. He didn't go
>>> to Harvard, but he did go to Princeton.
>>>
>>> Ellison is the son of an unwed mother who gave him up for adoption by
>>> her aunt and uncle, comfortably middle-class. That makes him the
>>> closest out of the group as a "regular guy".
>> And at least 2 of the above reached their position using business
>> practices that could be described as less than 100% honorable & above
>> board.
> 
> What do you expect from people who haven't graduated from Harvard? :P
> 
> Thank you,
> 
> Chris R.

i think the two people i am thinking of both did go to Harvard, i don't 
know if they graduated or not



-- 
Old MacDonald had an agricultural real estate tax abatement.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python PygLatin

2016-05-09 Thread alister
On Sun, 08 May 2016 21:51:18 -0700, Cai Gengyang wrote:

> I am guessing that the 2 you mentioned are Bill Gates and Larry Ellison
> ? I heard that they have tons of lawsuits against them in their career
> (anti-monopoly, anti-competitive laws filed against them both from the
> government and from individuals) ?
> 
> Paul Graham has this very interesting related essay on meanness and
> success --http://paulgraham.com/mean.html
> 
50% correct, although I was thinking more of "borrowed code/ip", 
doublespace is one term that springs to mind.

Also it is the accepted practice to use interleaved posting on this 
mailing list/newsgroup please do not  top post

 

-- 
  Goes (Went) over like a lead balloon.
-- 
https://mail.python.org/mailman/listinfo/python-list


pypi download links (e.g. for ansible)

2016-05-09 Thread Michael Ströder
HI!

Deep-links for downloading a specific version from PyPI seemed to work like 
this:

$ wget https://pypi.python.org/packages/source/a/ansible/ansible-2.0.1.0.tar.gz
[..]
Saving to: ‘ansible-2.0.1.0.tar.gz’

But this recent version does not work:

$ wget https://pypi.python.org/packages/source/a/ansible/ansible-2.0.2.0.tar.gz
[..]
HTTP request sent, awaiting response... 404 Not Found

Ciao, Michael.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pypi download links (e.g. for ansible)

2016-05-09 Thread harirammanohar
On Monday, May 9, 2016 at 3:30:31 PM UTC+5:30, Michael Ströder wrote:
> HI!
> 
> Deep-links for downloading a specific version from PyPI seemed to work like 
> this:
> 
> $ wget 
> https://pypi.python.org/packages/source/a/ansible/ansible-2.0.1.0.tar.gz
> [..]
> Saving to: 'ansible-2.0.1.0.tar.gz'
> 
> But this recent version does not work:
> 
> $ wget 
> https://pypi.python.org/packages/source/a/ansible/ansible-2.0.2.0.tar.gz
> [..]
> HTTP request sent, awaiting response... 404 Not Found
> 
> Ciao, Michael.

how its working for you, for me it says ssl connection error,if i do wget from 
linux as root user.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pygame easy create

2016-05-09 Thread harirammanohar
On Monday, May 9, 2016 at 10:50:47 AM UTC+5:30, [email protected] wrote:
> is there anyway (IDE/package) that allows me to create graphics/game just 
> like that (by instructing..., if i say create hills on the screen, it should 
> generate pygame code)Anyway :) :)

Atleast i tried with pyglet,felt that it will be easier than pygame. still 
again throwing me error some GL is missed, why they wont be straight forward in 
working if we select the env we have...

some sites says 2.7 and >=3(3.4+) will have pip module by default, but i am 
using 3.4.3 where i dont have pip and also tried python get-pip.py which also 
not worked..

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


Re: pygame easy create

2016-05-09 Thread harirammanohar
On Monday, May 9, 2016 at 10:50:47 AM UTC+5:30, [email protected] wrote:
> is there anyway (IDE/package) that allows me to create graphics/game just 
> like that (by instructing..., if i say create hills on the screen, it should 
> generate pygame code)Anyway :) :)

is there any way to create high graphics game using python, else its waste to 
learn pygame.

is there any module is there to create high grapihc game modules...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python PygLatin

2016-05-09 Thread Robin Koch

Am 08.05.2016 um 12:21 schrieb Cai Gengyang:

> If one looks at the Forbes List, you will see that there are 4
> programmers amongst the top ten richest people in the world (Bill
> Gates, Mark Zuckerberg, Larry Ellison and Jeff Bezos) , a very large
> percentage.

You might elaborate your knowledge about conditional probability as well.

P("X is programmer" | "X is in Forbes Top 10")

!=

P("X is in Forbes Top 10" | "X is programmer")

--
Robin Koch
--
https://mail.python.org/mailman/listinfo/python-list


Re: pypi download links (e.g. for ansible)

2016-05-09 Thread Michael Ströder
[email protected] wrote:
> On Monday, May 9, 2016 at 3:30:31 PM UTC+5:30, Michael Ströder wrote:
>> HI!
>>
>> Deep-links for downloading a specific version from PyPI seemed to work like 
>> this:
>>
>> $ wget 
>> https://pypi.python.org/packages/source/a/ansible/ansible-2.0.1.0.tar.gz
>> [..]
>> Saving to: 'ansible-2.0.1.0.tar.gz'
>>
>> But this recent version does not work:
>>
>> $ wget 
>> https://pypi.python.org/packages/source/a/ansible/ansible-2.0.2.0.tar.gz
>> [..]
>> HTTP request sent, awaiting response... 404 Not Found
> 
> how its working for you, for me it says ssl connection error,if i do wget 
> from linux as root user.

On my Linux installation the usually Mozilla web browser CA cert bundle is
installed.

Ciao, Michael.

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


Re: pypi download links (e.g. for ansible)

2016-05-09 Thread Steven D'Aprano
On Mon, 9 May 2016 08:00 pm, Michael Strc3b6der wrote:

> HI!
> 
> Deep-links for downloading a specific version from PyPI seemed to work
> like this:
> 
> $ wget
> https://pypi.python.org/packages/source/a/ansible/ansible-2.0.1.0.tar.gz
> [..]
> Saving to: ‘ansible-2.0.1.0.tar.gz’
> 
> But this recent version does not work:
> 
> $ wget
> https://pypi.python.org/packages/source/a/ansible/ansible-2.0.2.0.tar.gz
> [..]
> HTTP request sent, awaiting response... 404 Not Found


Do you have a question, or are you just sharing?

The Download button for 2.0.2.0 links to:

https://pypi.python.org/packages/b3/0e/5f3ee8884866a3d5e3b8ba86e9caa85ecdec75adabac8924b1c122339e7f/ansible-2.0.2.0.tar.gz

if that helps.


-- 
Steven

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


Re: pypi download links (e.g. for ansible)

2016-05-09 Thread Michael Ströder
Steven D'Aprano wrote:
> On Mon, 9 May 2016 08:00 pm, Michael Strc3b6der wrote:
> 
>> HI!
>>
>> Deep-links for downloading a specific version from PyPI seemed to work
>> like this:
>>
>> $ wget
>> https://pypi.python.org/packages/source/a/ansible/ansible-2.0.1.0.tar.gz
>> [..]
>> Saving to: ‘ansible-2.0.1.0.tar.gz’
>>
>> But this recent version does not work:
>>
>> $ wget
>> https://pypi.python.org/packages/source/a/ansible/ansible-2.0.2.0.tar.gz
>> [..]
>> HTTP request sent, awaiting response... 404 Not Found
> 
> 
> Do you have a question, or are you just sharing?
> 
> The Download button for 2.0.2.0 links to:
> 
> https://pypi.python.org/packages/b3/0e/5f3ee8884866a3d5e3b8ba86e9caa85ecdec75adabac8924b1c122339e7f/ansible-2.0.2.0.tar.gz

Yes, but in .spec files of openSUSE RPMs the more readable links above are used
and I'd like to keep it that way. And openSUSE build service checks whether it's
downloadable. It works for ansible-2.0.1.0 but not for 2.0.2.0.

Ciao, Michael.

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


Re: Python PygLatin

2016-05-09 Thread Rustom Mody
On Sunday, May 8, 2016 at 3:52:12 PM UTC+5:30, Cai Gengyang wrote:
> I just "clicked" through the lesson on Conditionals and Control Flows and am 
> on the lesson "PygLatin" .
> 
> This will hopefully be a more interesting and interactive lesson because I 
> will be building a PygLatin Translator ...
> 
> It seems to me like it will take a long time before I can reach the point 
> where I can become a master of programming languages and even create new 
> programming languages and technologies. This is a long road ahead, but I 
> believe it is worth it because the power of a new technology does eventually 
> translate into money. If one looks at the Forbes List, you will see that 
> there are 4 programmers amongst the top ten richest people in the world (Bill 
> Gates, Mark Zuckerberg, Larry Ellison and Jeff Bezos) , a very large 
> percentage. Science and Technology is in a sense the most egalitarian field 
> in the world, because it involves using your brains and creativity. You don't 
> need to have a father who is a director at Goldman Sachs or a mother who is 
> the admissions officer at Harvard to succeed in this line. All you need is 
> have the ability to create something that many users love to use.



Here are some physical creations which humans have made:
  1. Petronas [1]
  2. Chartres [2]
  3. Egypt pyramids [3]
  4. Arunachala temple [4]

What do you think is the ratio of those that designed/conceptualized
these to those who laid stone/bricks/steel? My estimate 1:100 to
1:1.

Software is no different.  If you train as a pilot you have a better
chance of landing the lead position on the Mars-mission than if you
train as a programmer and hope to become Bill Gates II.

Helpful to read "It doesnt matter" [5] in this respect. Dont get fooled by the
title. What it really says is that as IT transitions from innovation
to utility, it matters more and more but only in a negative sense. eg
if the power or the water or the roads are bad we get very
indignant. When they are fine the so-called 'blue-collar-workers' who
provide them are faceless, invisible.

Cost gravity [6] explains the mechanics of how that happens

In other words we IT-professionals are the blue-collar workers of the
21st century.  Why is this not more widely undersood? Because
CS-education is grossly out of sync with IT-practice. See [7] -- CS
education is habitually taught as though only only the first column
exists. In the IT world its mostly the second that counts.

Steven reminds of the caste-system that the super-rich are usually
sons of the rich in our field like anywhere else.

This is true but misunderstood.  It is not that money begets more
money like some kind of magnet.  Its rather that the rich have a
certain freedom to their thinking/outlook.  An outlook that others too
can with some effort emulate.  Triune brain [8] explains that we have
3 brains corresponding to our evolutionary stages:
  - reptilian
  - mammalian
  - specifically human (cortex)

When we are in survive/sex mode we are essentially reptiles. When we
are in emotional mode we are a bit better -- mammals.  If we can get
beyond both we can be truly human.  This is hard for anyone, but for
the poor the survival needs predominate so its harder. For some
thoughts on switching from the more animal to the more human aspects
of our functioning see [9]
[I guess the advantage the rich have with survival is lost to sex]

2 Refs
==

1. 
https://upload.wikimedia.org/wikipedia/commons/6/6d/Petronas_Twin_Towers_2010_April.jpg

2. http://whc.unesco.org/uploads/thumbs/site_0081_0001-750-0-20151104132433.jpg
3. https://upload.wikimedia.org/wikipedia/commons/a/af/All_Gizah_Pyramids.jpg
4. https://arunachaleshwarar.files.wordpress.com/2012/09/tem.jpg
5. https://hbr.org/2003/05/it-doesnt-matter
6. http://content.cultureandempire.com/preface.html
7. http://blog.languager.org/2010/02/service-and-product-mindsets.html
8. http://www.kheper.net/topics/intelligence/MacLean.htm
9. http://blog.languager.org/2010/05/declaration-imperation-and-language.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python PygLatin

2016-05-09 Thread Michael Torrie
On 05/08/2016 04:21 AM, Cai Gengyang wrote:
> This is a long
> road ahead, but I believe it is worth it because the power of a new
> technology does eventually translate into money. 

If this is your prime motivation, I think you'll be very disappointed.
A good programmer certainly can make a good salary.  But the road to
riches? Well that's actually relatively rare. Just look at the the Apple
Store or Google Play Store.  Thousands of games and apps and very few
small developers making the big dollars through it.  Some manage to get
lucky but most do not.

Really good programmers do it because they enjoy doing it, whether it's
the problem solving aspects, or maybe because they enjoy creating a
product that is useful to others.  While computer programming is a
learned skill, some have more aptitude and intuition for it than others.
 If you honestly enjoy it then you'll do fine.  If you don't find it
intellectually stimulating then you'll definitely struggle as far as a
career path goes.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pypi download links (e.g. for ansible)

2016-05-09 Thread Chris Warrick
On 9 May 2016 at 13:35, Michael Ströder  wrote:
> Steven D'Aprano wrote:
>> On Mon, 9 May 2016 08:00 pm, Michael Strc3b6der wrote:
>>
>>> HI!
>>>
>>> Deep-links for downloading a specific version from PyPI seemed to work
>>> like this:
>>>
>>> $ wget
>>> https://pypi.python.org/packages/source/a/ansible/ansible-2.0.1.0.tar.gz
>>> [..]
>>> Saving to: ‘ansible-2.0.1.0.tar.gz’
>>>
>>> But this recent version does not work:
>>>
>>> $ wget
>>> https://pypi.python.org/packages/source/a/ansible/ansible-2.0.2.0.tar.gz
>>> [..]
>>> HTTP request sent, awaiting response... 404 Not Found
>>
>>
>> Do you have a question, or are you just sharing?
>>
>> The Download button for 2.0.2.0 links to:
>>
>> https://pypi.python.org/packages/b3/0e/5f3ee8884866a3d5e3b8ba86e9caa85ecdec75adabac8924b1c122339e7f/ansible-2.0.2.0.tar.gz
>
> Yes, but in .spec files of openSUSE RPMs the more readable links above are 
> used
> and I'd like to keep it that way. And openSUSE build service checks whether 
> it's
> downloadable. It works for ansible-2.0.1.0 but not for 2.0.2.0.
>
> Ciao, Michael.
>
> --
> https://mail.python.org/mailman/listinfo/python-list

PyPI URLs were changed recently. There is, however, a new supported
way to get dependable URLs:
https://bitbucket.org/pypa/pypi/issues/438/backwards-compatible-un-hashed-package

The current link:
https://files.pythonhosted.org/packages/source/a/ansible/ansible-2.0.1.0.tar.gz

(URLs in the pypi.io domain were used briefly and will still work)

-- 
Chris Warrick 
PGP: 5EAAEA16
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pygame easy create

2016-05-09 Thread sohcahtoa82
On Monday, May 9, 2016 at 3:15:45 AM UTC-7, [email protected] wrote:
> On Monday, May 9, 2016 at 10:50:47 AM UTC+5:30, [email protected] wrote:
> > is there anyway (IDE/package) that allows me to create graphics/game just 
> > like that (by instructing..., if i say create hills on the screen, it 
> > should generate pygame code)Anyway :) :)
> 
> Atleast i tried with pyglet,felt that it will be easier than pygame. 
> still again throwing me error some GL is missed, why they wont be straight 
> forward in working if we select the env we have...
> 
> some sites says 2.7 and >=3(3.4+) will have pip module by default, but i am 
> using 3.4.3 where i dont have pip and also tried python get-pip.py which also 
> not worked..

"still again throwing me error some GL is missed"

Can you say *EXACTLY* what the error is?  And can you copy/paste the relevant 
lines of code that lead to that error?

Also, judging from your other messages, it looks like you might be needing to 
read the Python or PyGame tutorials.  Programming is problem solving.  You 
can't just saying "Draw a hill" and PyGame (or whatever module you're using) 
will draw a hill.  You need to write code that describes how to draw a hill.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: String concatenation (was: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement?)

2016-05-09 Thread Michael Selik
You're saying that wasn't a coded message?

On Sun, May 8, 2016, 10:44 PM srinivas devaki 
wrote:

> I'm so sorry, forgot to lock my phone.
> On May 9, 2016 9:01 AM, "srinivas devaki" 
> wrote:
>
> > f be gfdnbh be b GB GB BH GB vbjfhjb GB bffbbubbv GB hbu hbu
> > fjbjfbbbufhbvh VB have fqbgvfb NB bb GB GB GB GB bbu GB vu GB vu GB
> GB
> > b GB fbufjnb BH GB GB bvvfbubbjubuv GB b fbufbbby GB bfff GB f GB
> > bbbu GB GB ffinj GB vh vh fjb GB fj GB h h GB gjfthey're the b GB gjf GBG
> > GBG q GB fbb b bh VB ffbff GBG fbfvrgv
> > On May 9, 2016 7:49 AM, "Chris Angelico"  wrote:
> >
> > On Mon, May 9, 2016 at 10:44 AM, Thomas 'PointedEars' Lahn
> >  wrote:
> > > With the “%” string operator (deprecated), str.format(), and
> > str.Template,
> > > you can use other values in string values even without concatenation.
> >
> > Not deprecated. Don't spread FUD.
> >
> > > Finally, with SQL you should prefer Prepared Statements and Stored
> > > Procedures, not bare strings, to avoid SQL injection:
> > >
> > > 
> >
> > He is safe. He's using parameterized queries.
> >
> > > Also, it would be a good idea if you posted under your real name.
> > Internet
> > > is the thing with cables; Usenet is the thing with people.  I for one
> > tend
> > > to avoid communicating with few-letter entities; exceptions to that
> would
> > > probably include only E.T., M.J., ALF, and K.I.T.T.
> >
> > I'm not using Usenet, Mr PointedEars.
> >
> > ChrisA
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
> >
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A problem with classes - derived type

2016-05-09 Thread Paulo da Silva
Às 05:20 de 09-05-2016, Paulo da Silva escreveu:

Thank you Yann and Peter.

I really didn't know anything about those "things".
So far I have worked a lot with classes but they are written by me.
Now I needed to derive pandas.Series (for example) and it has some
methods that return pandas.Series objects. And I needed to return the
derived object, not the pandas.Series one.

The problem is now fixed.

I'll find some time to read a little more about this to improve my pyhon
knowledge.

Thank you very much.

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


json.loads(...) ValueError: Expecting value: line 1 column 1 (char 0)

2016-05-09 Thread zljubisic
Hi,

in python3 my variable looks like this:

a = b'{"uuid":"5730e8666ffa02.34177329","error":""}'
str(a) = 'b\'{"uuid":"5730e8666ffa02.34177329","error":""}\''

If I execute the following command I get the error:

>>> json.loads(str(a))
Traceback (most recent call last):
  File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 
2016.1.2\helpers\pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec
exec(exp, global_vars, local_vars)
  File "", line 1, in 
  File "C:\Program Files\Python34\lib\json\__init__.py", line 318, in loads
return _default_decoder.decode(s)
  File "C:\Program Files\Python34\lib\json\decoder.py", line 343, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Program Files\Python34\lib\json\decoder.py", line 361, in raw_decode
raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)

Why I am getting this error?
If I set variable a to the '{"uuid":"5730e8666ffa02.34177329","error":""}' 
everything works as expected.

Regards.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: json.loads(...) ValueError: Expecting value: line 1 column 1 (char 0)

2016-05-09 Thread Peter Otten
[email protected] wrote:

> Hi,
> 
> in python3 my variable looks like this:
> 
> a = b'{"uuid":"5730e8666ffa02.34177329","error":""}'
> str(a) = 'b\'{"uuid":"5730e8666ffa02.34177329","error":""}\''
> 
> If I execute the following command I get the error:
> 
 json.loads(str(a))
> Traceback (most recent call last):
>   File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition
>   2016.1.2\helpers\pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec
> exec(exp, global_vars, local_vars)
>   File "", line 1, in 
>   File "C:\Program Files\Python34\lib\json\__init__.py", line 318, in
>   loads
> return _default_decoder.decode(s)
>   File "C:\Program Files\Python34\lib\json\decoder.py", line 343, in
>   decode
> obj, end = self.raw_decode(s, idx=_w(s, 0).end())
>   File "C:\Program Files\Python34\lib\json\decoder.py", line 361, in
>   raw_decode
> raise ValueError(errmsg("Expecting value", s, err.value)) from None
> ValueError: Expecting value: line 1 column 1 (char 0)
> 
> Why I am getting this error?
> If I set variable a to the '{"uuid":"5730e8666ffa02.34177329","error":""}'
> everything works as expected.

Look at the traceback: "line 1 column 1 (char 0)" mentioned in the error 
message is the leading "b".

When you convert a byte string to unicode with str(bytestr) the "b" prefix 
and the quotation marks are part of the resulting string, but not valid 
JSON. Try a.decode() instead of str(a):

>>> a = b'{"uuid":"5730e8666ffa02.34177329","error":""}'
>>> json.loads(a.decode())
{'error': '', 'uuid': '5730e8666ffa02.34177329'}


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


Re: json.loads(...) ValueError: Expecting value: line 1 column 1 (char 0)

2016-05-09 Thread MRAB

On 2016-05-09 20:56, [email protected] wrote:

Hi,

in python3 my variable looks like this:

a = b'{"uuid":"5730e8666ffa02.34177329","error":""}'
str(a) = 'b\'{"uuid":"5730e8666ffa02.34177329","error":""}\''

If I execute the following command I get the error:


json.loads(str(a))

Traceback (most recent call last):
  File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 
2016.1.2\helpers\pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec
exec(exp, global_vars, local_vars)
  File "", line 1, in 
  File "C:\Program Files\Python34\lib\json\__init__.py", line 318, in loads
return _default_decoder.decode(s)
  File "C:\Program Files\Python34\lib\json\decoder.py", line 343, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Program Files\Python34\lib\json\decoder.py", line 361, in raw_decode
raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)

Why I am getting this error?
If I set variable a to the '{"uuid":"5730e8666ffa02.34177329","error":""}' 
everything works as expected.


The b-prefix is Python-specific. It's not valid JSON syntax.

The JSON format is defined here:

http://www.json.org/

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


Re: json.loads(...) ValueError: Expecting value: line 1 column 1 (char 0)

2016-05-09 Thread Ben Bacarisse
[email protected] writes:

> in python3 my variable looks like this:
>
> a = b'{"uuid":"5730e8666ffa02.34177329","error":""}'
> str(a) = 'b\'{"uuid":"5730e8666ffa02.34177329","error":""}\''
>
> If I execute the following command I get the error:
>
 json.loads(str(a))
> Traceback (most recent call last):
>   File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 
> 2016.1.2\helpers\pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec
> exec(exp, global_vars, local_vars)
>   File "", line 1, in 
>   File "C:\Program Files\Python34\lib\json\__init__.py", line 318, in loads
> return _default_decoder.decode(s)
>   File "C:\Program Files\Python34\lib\json\decoder.py", line 343, in decode
> obj, end = self.raw_decode(s, idx=_w(s, 0).end())
>   File "C:\Program Files\Python34\lib\json\decoder.py", line 361, in 
> raw_decode
> raise ValueError(errmsg("Expecting value", s, err.value)) from None
> ValueError: Expecting value: line 1 column 1 (char 0)
>
> Why I am getting this error?

The result of str(a) is not a valid JSON string.  It starts with a b but
a JSON string must start with a digit of one of -, ", {, [, t, f, n (the
letters being legal only if they are the start of true, false or null.

In fact (in Python 3), passing bytes to str() without an encoding is a
special case -- you get an informal string representation.  I'm not sure
you can be sure what you get though I imagine it's designed to be the
same as Python 2 gave.

> If I set variable a to the
> '{"uuid":"5730e8666ffa02.34177329","error":""}' everything works as
> expected.

That string starts with { so it's OK.  You probably what something like

 json.loads(str(a, 'ascii'))

or maybe 'utf-8' or 'windows-1285' or... well you get the idea.  You
need to say how the bytes should be turned into string characters.

-- 
Ben.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: json.loads(...) ValueError: Expecting value: line 1 column 1 (char 0)

2016-05-09 Thread Terry Reedy

On 5/9/2016 3:56 PM, [email protected] wrote:

Hi,

in python3 my variable looks like this:

a = b'{"uuid":"5730e8666ffa02.34177329","error":""}'
str(a) = 'b\'{"uuid":"5730e8666ffa02.34177329","error":""}\''

If I execute the following command I get the error:


json.loads(str(a))

Traceback (most recent call last):
  File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 
2016.1.2\helpers\pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec
exec(exp, global_vars, local_vars)
  File "", line 1, in 
  File "C:\Program Files\Python34\lib\json\__init__.py", line 318, in loads
return _default_decoder.decode(s)
  File "C:\Program Files\Python34\lib\json\decoder.py", line 343, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Program Files\Python34\lib\json\decoder.py", line 361, in raw_decode
raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)

Why I am getting this error?
If I set variable a to the '{"uuid":"5730e8666ffa02.34177329","error":""}' 
everything works as expected.


This means that the two versions of 'a' are not the same.  So what you 
should have done to debug is print the second to see what you actually 
passed to json.


Editorial: Programming classes should teach basic debugging better. I 
have seen numerous newbie Stackoverflow questions where the person 
should have started with adding a print statement before posting a question.


--
Terry Jan Reedy

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


Are imports supposed to be like this?

2016-05-09 Thread Brendan Abel
Consider the following example python package where `a.py` and `b.py`
depend on each other:

/package
__init__.py
a.py
b.py


There are several ways I could import the "a.py" module in "b.py"

import package.a   # Absolute import
import package.a as a_mod  # Absolute import bound to different name
from package import a  # Alternate absolute import
import a   # Implicit relative import (deprecated, py2
only)
from . import a# Explicit relative import

Unfortunately, only the 1st and 4th syntax actually work when you have
circular dependencies (the rest all raise `ImportError` or
`AttributeError`), and the 4th syntax only works in python 2 and is
generally discouraged because of the possibility of name conflicts.

I'd much rather use relative imports, or the "from x import y" syntax, or
at least be able to use the "as" import syntax.  If I have a deeply nested
package, the imports become unruly rather quickly, and I have to use that
long, ugly name throughout the entire module!

import package.subpackage.submodule.module  # fugly!

Are imports designed to work this way, or is this a bug in the import
machinery?  What reasoning is there for the first syntax to work, but all
the others should fail?  Admittedly, I haven't used Python3 yet, does it
fix this?  It seems odd to me that the documentation seems to encourage
relative imports or at least the "from x.y.z import a" forms of imports,
yet they don't work the same as "import x.y.z.a".


//Brendan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Are imports supposed to be like this?

2016-05-09 Thread Chris Angelico
On Tue, May 10, 2016 at 9:54 AM, Brendan Abel <[email protected]> wrote:
> Consider the following example python package where `a.py` and `b.py`
> depend on each other:
>
> /package
> __init__.py
> a.py
> b.py
>
>
> There are several ways I could import the "a.py" module in "b.py"
>
> import package.a   # Absolute import
> import package.a as a_mod  # Absolute import bound to different name
> from package import a  # Alternate absolute import
> import a   # Implicit relative import (deprecated, py2
> only)
> from . import a# Explicit relative import
>
> Unfortunately, only the 1st and 4th syntax actually work when you have
> circular dependencies (the rest all raise `ImportError` or
> `AttributeError`), and the 4th syntax only works in python 2 and is
> generally discouraged because of the possibility of name conflicts.

The fifth is the one that I would recommend. Can you give an example
of a circular dependency that makes it fail? Here's the trivial case
that I tried:

rosuav@sikorsky:~/tmp$ mkdir package
rosuav@sikorsky:~/tmp$ touch package/__init__.py
rosuav@sikorsky:~/tmp$ cat >package/a.py
from . import b
def func_a(x):
print("func_a: %d" % x)
if x % 2: b.func_b(x-1)
rosuav@sikorsky:~/tmp$ cat >package/b.py
from . import a
def func_b(x):
print("func_b: %d" % x)
if x % 2: a.func_a(x-1)
rosuav@sikorsky:~/tmp$ python3
Python 3.6.0a0 (default:98678738b7e9, May  2 2016, 13:37:04)
[GCC 5.3.1 20160409] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import package.a
>>> package.a.func_a(5)
func_a: 5
func_b: 4
>>> import package.b
>>> package.b.func_b(5)
func_b: 5
func_a: 4
>>>

The imports work fine as long as you use strictly "from . import
modulename", and not "from .modulename import objectname". Circular
imports of the latter form will indeed fail, but if you have
non-circular imports, you can stop them from failing by forcing module
load order:

rosuav@sikorsky:~/tmp$ cat package/a.py
from .b import func_b
def func_a(x):
print("func_a: %d" % x)
if x % 2: func_b(x-1)
rosuav@sikorsky:~/tmp$ cat >package/__init__.py
from . import a
from . import b


This does prevent lazy loading, though, so if your circular imports
are in an optional part of the package (and one that takes a long time
to load), you might want to consider setting it up some other way.

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


Re: Are imports supposed to be like this?

2016-05-09 Thread Random832
On Mon, May 9, 2016, at 19:54, Brendan Abel wrote:
> Consider the following example python package where `a.py` and `b.py`
> depend on each other:
> 
> /package
> __init__.py
> a.py
> b.py
> 
> 
> There are several ways I could import the "a.py" module in "b.py"
> 
> import package.a   # Absolute import
> import package.a as a_mod  # Absolute import bound to different name
> from package import a  # Alternate absolute import
> import a   # Implicit relative import (deprecated,
> py2
> only)
> from . import a# Explicit relative import

Can you show a complete example of what doesn't work with one or more of
these?

Because if I have:
- empty package/__init__.py
- package/a.py consisting of only "from . import b"
- package/b.py consisting of only "from . import a"
- in the directory containing 'package', running python 3.5
interactively, executing:
>>> import package.a

everything seems to work.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: json.loads(...) ValueError: Expecting value: line 1 column 1 (char 0)

2016-05-09 Thread Steven D'Aprano
On Tue, 10 May 2016 09:07 am, Terry Reedy wrote:

> Editorial: Programming classes should teach basic debugging better. I
> have seen numerous newbie Stackoverflow questions where the person
> should have started with adding a print statement before posting a
> question.

+1



-- 
Steven

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


Re: String concatenation

2016-05-09 Thread Steven D'Aprano
On Tue, 10 May 2016 07:21 am, Thomas 'PointedEars' Lahn wrote:

> Chris Angelico wrote:
> 
>> On Mon, May 9, 2016 at 10:44 AM, Thomas 'PointedEars' Lahn
>>  wrote:
>>> With the “%” string operator (deprecated), str.format(), and
>>> str.Template, you can use other values in string values even without
>>> concatenation.
>> 
>> Not deprecated. Don't spread FUD.
> 
> If only you cared to read what I referred to:
>
> ,-

That is excellent advice Thomas!

If only you had followed it yourself, instead of blindly and mechanically
copying and pasting. If you had bothered to actually read it, you would
have seen that *nowhere* does it say that the % string operator is
deprecated.

Deprecation has a specific meaning involving a formal process of removing a
feature from the language. It doesn't merely mean "this old feature has
quirks and we think you should use this new feature instead". Some of the
core developers like `format` better and think that people should use it in
preference to the % string operator. That much is true. But that is far
from being deprecated.


> Note the key words: “old”, “quirks”, “errors”.

Irrelevant to the question of deprecation.

Floats are old (they go back to the first release of Python), they have many
quirks (x + y - x is not necessarily equal to y), and people make many
errors with floats. Does this mean they are deprecated? Of course not.


-- 
Steven

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


Re: String concatenation

2016-05-09 Thread Chris Angelico
On Tue, May 10, 2016 at 12:32 PM, Steven D'Aprano  wrote:
> Floats are old (they go back to the first release of Python), they have many
> quirks (x + y - x is not necessarily equal to y), and people make many
> errors with floats. Does this mean they are deprecated? Of course not.

Careful there Steven - now that cdecimal is in core, people might
start saying that. Particularly if (as is periodically requested, and
which I think would be a good idea) Decimal literals become a thing.
And the removal of core types HAS happened. Correct me if I'm wrong,
but didn't the first release of Python have only the short integer
type, and then a completely new 'long' type was added? Automatic
promotion blurred the distinction, and then Python 3.0 removed the
'int' type and renamed 'long'. So it's theoretically possible for
Decimal to replace float...

... except that that would actually be a bad idea, which a lot of
people don't realize.

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


Re: String concatenation

2016-05-09 Thread Rustom Mody
On Tuesday, May 10, 2016 at 2:52:13 AM UTC+5:30, Thomas 'PointedEars' Lahn 
wrote:
> Chris Angelico wrote:
> 
> > On Mon, May 9, 2016 at 10:44 AM, Thomas 'PointedEars' Lahn wrote:
> >> Also, it would be a good idea if you posted under your real name. 
> >> Internet is the thing with cables; Usenet is the thing with people.
> >> I for one tend to avoid communicating with few-letter entities;
> >> exceptions to that would probably include only E.T., M.J., ALF, and
> >> K.I.T.T.
> > 
> > I'm not using Usenet, Mr PointedEars.
> 
> I don't care.  This basic courtesy extended to strangers whose help you seek 
> originates in real life, not Usenet.

And it is objectionable to discriminate on people's names; the same way it is 
objectionable to discriminate on people's skin-color, religion, country, sex etc

See: 
http://www.alphr.com/computing/1000378/facebook-rejects-native-american-names-as-fake-again
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: json.loads(...) ValueError: Expecting value: line 1 column 1 (char 0)

2016-05-09 Thread Rustom Mody
On Tuesday, May 10, 2016 at 7:43:17 AM UTC+5:30, Steven D'Aprano wrote:
> On Tue, 10 May 2016 09:07 am, Terry Reedy wrote:
> 
> > Editorial: Programming classes should teach basic debugging better. I
> > have seen numerous newbie Stackoverflow questions where the person
> > should have started with adding a print statement before posting a
> > question.
> 
> +1

Maybe the tutorial should have a small chapter on debugging (introspecting) 
showing how to use
- print
- type
- dir
And then iterating on these
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pygame easy create

2016-05-09 Thread harirammanohar
On Monday, May 9, 2016 at 11:12:47 PM UTC+5:30, [email protected] wrote:
> On Monday, May 9, 2016 at 3:15:45 AM UTC-7, [email protected] wrote:
> > On Monday, May 9, 2016 at 10:50:47 AM UTC+5:30, [email protected] wrote:
> > > is there anyway (IDE/package) that allows me to create graphics/game just 
> > > like that (by instructing..., if i say create hills on the screen, it 
> > > should generate pygame code)Anyway :) :)
> > 
> > Atleast i tried with pyglet,felt that it will be easier than pygame. 
> > still again throwing me error some GL is missed, why they wont be straight 
> > forward in working if we select the env we have...
> > 
> > some sites says 2.7 and >=3(3.4+) will have pip module by default, but i am 
> > using 3.4.3 where i dont have pip and also tried python get-pip.py which 
> > also not worked..
> 
> "still again throwing me error some GL is missed"
> 
> Can you say *EXACTLY* what the error is?  And can you copy/paste the relevant 
> lines of code that lead to that error?
> 
> Also, judging from your other messages, it looks like you might be needing to 
> read the Python or PyGame tutorials.  Programming is problem solving.  You 
> can't just saying "Draw a hill" and PyGame (or whatever module you're using) 
> will draw a hill.  You need to write code that describes how to draw a hill.


code:

#!/home/python/3.4.3/python
import os,sys
sys.path.append('/home/python/3.4.3/custommodules/lib/python3.4/site-packages')
import pyglet

window = pyglet.window.Window()

label = pyglet.text.Label('Hello, world',
  font_name='Times New Roman',
  font_size=36,
  x=window.width//2, y=window.height//2,
  anchor_x='center', anchor_y='center')


@window.event
def on_draw():
window.clear()
label.draw()

pyglet.app.run()


op:
-bash-4.1$ ./pygletpgm.py
Traceback (most recent call last):
  File "./pygletpgm.py", line 5, in 
import pyglet
ImportError: No module named 'pyglet'


I am able to successfully install pyglet module in custommodules...




another issue:

-bash-4.1$ python get-pip.py
/tmp/tmpUdukeA/pip.zip/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: 
InsecurePlatformWarning: A true SSLContext object is not available. This 
prevents urllib3 from configuring SSL appropriately and may cause certain SSL 
connections to fail. For more information, see 
https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
Collecting pip
/tmp/tmpUdukeA/pip.zip/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: 
InsecurePlatformWarning: A true SSLContext object is not available. This 
prevents urllib3 from configuring SSL appropriately and may cause certain SSL 
connections to fail. For more information, see 
https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
/tmp/tmpUdukeA/pip.zip/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: 
InsecurePlatformWarning: A true SSLContext object is not available. This 
prevents urllib3 from configuring SSL appropriately and may cause certain SSL 
connections to fail. For more information, see 
https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  Could not find a version that satisfies the requirement pip (from versions: )
No matching distribution found for pip


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


Re: pygame easy create

2016-05-09 Thread harirammanohar
On Monday, May 9, 2016 at 11:12:47 PM UTC+5:30, [email protected] wrote:
> On Monday, May 9, 2016 at 3:15:45 AM UTC-7, [email protected] wrote:
> > On Monday, May 9, 2016 at 10:50:47 AM UTC+5:30, [email protected] wrote:
> > > is there anyway (IDE/package) that allows me to create graphics/game just 
> > > like that (by instructing..., if i say create hills on the screen, it 
> > > should generate pygame code)Anyway :) :)
> > 
> > Atleast i tried with pyglet,felt that it will be easier than pygame. 
> > still again throwing me error some GL is missed, why they wont be straight 
> > forward in working if we select the env we have...
> > 
> > some sites says 2.7 and >=3(3.4+) will have pip module by default, but i am 
> > using 3.4.3 where i dont have pip and also tried python get-pip.py which 
> > also not worked..
> 
> "still again throwing me error some GL is missed"
> 
> Can you say *EXACTLY* what the error is?  And can you copy/paste the relevant 
> lines of code that lead to that error?
> 
> Also, judging from your other messages, it looks like you might be needing to 
> read the Python or PyGame tutorials.  Programming is problem solving.  You 
> can't just saying "Draw a hill" and PyGame (or whatever module you're using) 
> will draw a hill.  You need to write code that describes how to draw a hill.

yeah coding is a problem solving as you said, its right but i have asked any 
utility is there for easy design in the same fashion

okay can you answser my question, using python modules (pygame/pyglet whatever 
it may be) can we design games with higher graphics (like world of tanks, 
freedom fighter, mission impossible:rouge nation, contract killer etc)
-- 
https://mail.python.org/mailman/listinfo/python-list


An educational site written in Python (from YCombinator's RFS)

2016-05-09 Thread Cai Gengyang
Ok, so after reading YCombinator's RFS, I have decided that I want to work on 
this :


---

EDUCATION

If we can fix education, we can eventually do everything else on this list.
The first attempts to use technology to fix education have focused on using the 
Internet to distribute traditional content to a wider audience. This is good, 
but the Internet is a fundamentally different medium and capable of much more.

Solutions that combine the mass scale of technology with one-on-one in-person 
interaction are particularly interesting to us.

This may not require a "breakthrough" technology in the classical sense, but at 
a minimum it will require very new ways of doing things.

---

I want to create such a site using Python. What are the various steps I need to 
take to create such a site ? This is a big project, but one that is worth doing 
... Any suggestions / help appreciated ? Thanks alot


Gengyang
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: String concatenation

2016-05-09 Thread Steven D'Aprano
On Tuesday 10 May 2016 13:45, Rustom Mody wrote:

> See:
> http://www.alphr.com/computing/1000378/facebook-rejects-native-american-
names-as-fake-again


Somebody should set up a kick-starter to pay someone to change their legal 
name to "Facebook-Are-Arseholes", then open a Facebook account with it. I'd 
contribute a couple of bucks.

("That's MISTER Facebook-Are-Arseholes to you!")

Unfortunately, Australia's naming laws almost certainly wouldn't allow such 
a name. But I think the US would.


-- 
Steve

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