comp.lang.python - 26 new messages in 9 topics - digest
comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en
comp.lang.python@googlegroups.com
Today's topics:
* efficient way to process data - 9 messages, 4 authors
http://groups.google.com/group/comp.lang.python/t/f7c2c58424bf2b3e?hl=en
* Problem writing some strings (UnicodeEncodeError) - 4 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/08d2e6a4bc11d1c3?hl=en
* Python: 404 Error when trying to login a webpage by using 'urllib' and '
HTTPCookieProcessor' - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/bf0e28e020a02c69?hl=en
* Python example source code - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/8594472fa123f77e?hl=en
* extracting string.Template substitution placeholders - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/e98ada5213c4b344?hl=en
* plotting slows down - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/22f280b151f3c221?hl=en
* 'Straße' ('Strasse') and Python 2 - 5 messages, 4 authors
http://groups.google.com/group/comp.lang.python/t/93ddbbff468ab95d?hl=en
* L[:] - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/8c4883bbe077624c?hl=en
* Module depositary - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/98da54fb4adeccb4?hl=en
==============================================================================
TOPIC: efficient way to process data
http://groups.google.com/group/comp.lang.python/t/f7c2c58424bf2b3e?hl=en
==============================================================================
== 1 of 9 ==
Date: Sun, Jan 12 2014 11:53 am
From: Petite Abeille
On Jan 12, 2014, at 8:23 PM, Larry Martell <larry.martell@gmail.com> wrote:
> AFAIK, there is no way to do this in SQL.
Sounds like a job for window functions (aka analytic functions) [1][2].
[1] http://www.postgresql.org/docs/9.3/static/tutorial-window.html
[2] http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions004.htm#SQLRF06174
== 2 of 9 ==
Date: Sun, Jan 12 2014 2:18 pm
From: Chris Angelico
On Mon, Jan 13, 2014 at 6:53 AM, Petite Abeille
<petite.abeille@gmail.com> wrote:
> On Jan 12, 2014, at 8:23 PM, Larry Martell <larry.martell@gmail.com> wrote:
>
>> AFAIK, there is no way to do this in SQL.
>
> Sounds like a job for window functions (aka analytic functions) [1][2].
That's my thought too. I don't think MySQL has them, though, so it's
either going to have to be done in Python, or the database back-end
will need to change. Hard to say which would be harder.
ChrisA
== 3 of 9 ==
Date: Sun, Jan 12 2014 2:43 pm
From: Dennis Lee Bieber
On Sun, 12 Jan 2014 14:23:17 -0500, Larry Martell <larry.martell@gmail.com>
declaimed the following:
>I have an python app that queries a MySQL DB. The query has this form:
>
>SELECT a, b, c, d, AVG(e), STD(e), CONCAT(x, ',', y) as f
>FROM t
>GROUP BY a, b, c, d, f
>
>x and y are numbers (378.18, 2213.797 or 378.218, 2213.949 or
>10053.490, 2542.094).
>
Decimal (Numeric) or floating/real. If the latter, the internal storage
may not be exact (378.1811111111 and 378.179999999 may both "display" as
378.18, but will not match for grouping).
>The business issue is that if either x or y in 2 rows that are in the
>same a, b, c, d group are within 1 of each other then they should be
>grouped together. And to make it more complicated, the tolerance is
>applied as a rolling continuum. For example, if the x and y in a set
>of grouped rows are:
>
As I understand group by, it will first group by "a", WITHIN the "a"
groups it will then group by "b"... Probably not a matter germane to the
problem as you are concerning yourself with the STRING representation of
"x" and "y" with a comma delimiter -- which is only looked at if the
"a,b,c,d" are equal... Thing is, a string comparison is going to operate
strictly left to right -- it won't even see your "y" value unless all the
"x" value is equal.
You may need to operate using subselects... So that you can specify
something like
where abs(s1.x -s2.x) < tolerance or abs(s1.y-s2.y) < tolerance
and (s1.a = s2.a ... s1.d = s2.d)
s1/s1 are the subselects (you may need a primary key <> primary key to
avoid having it output a record where the two subselects are for the SAME
record -- or maybe not, since you /do/ want that record also output). Going
to be a costly query since you are basically doing
foreach r1 in s1
foreach r2 in s2
emit r2 when...
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
== 4 of 9 ==
Date: Sun, Jan 12 2014 3:27 pm
From: Chris Angelico
On Mon, Jan 13, 2014 at 6:23 AM, Larry Martell <larry.martell@gmail.com> wrote:
> I have an python app that queries a MySQL DB. The query has this form:
>
> SELECT a, b, c, d, AVG(e), STD(e), CONCAT(x, ',', y) as f
> FROM t
> GROUP BY a, b, c, d, f
>
> x and y are numbers (378.18, 2213.797 or 378.218, 2213.949 or
> 10053.490, 2542.094).
>
> The business issue is that if either x or y in 2 rows that are in the
> same a, b, c, d group are within 1 of each other then they should be
> grouped together. And to make it more complicated, the tolerance is
> applied as a rolling continuum. For example, if the x and y in a set
> of grouped rows are:
>
> row 1: 1.5, 9.5
> row 2: 2.4, 20.8
> row 3: 3.3, 40.6
> row 4: 4.2, 2.5
> row 5: 5.1, 10.1
> row 6: 6.0, 7.9
> row 7: 8.0, 21.0
> row 8: 100, 200
>
> 1 through 6 get combined because all their X values are within the
> tolerance of some other X in the set that's been combined. 7's Y value
> is within the tolerance of 2's Y, so that should be combined as well.
> 8 is not combined because neither the X or Y value is within the
> tolerance of any X or Y in the set that was combined.
Trying to get my head around this a bit more. Are columns a/b/c/d
treated as a big category (eg type, brand, category, model), such that
nothing will ever be grouped that has any difference in those four
columns? If so, we can effectively ignore them and pretend we have a
table with exactly one set (eg stick a WHERE clause onto the query
that stipulates their values). Then what you have is this:
* Aggregate based on proximity of x and y
* Emit results derived from e
Is that correct?
So here's my way of writing it.
* Subselect: List all values for x, in order, and figure out which
ones are less than the previous value plus one
* Subselect: Ditto, for y.
* Outer select: Somehow do an either-or group. I'm not quite sure how
to do that part, actually!
A PGSQL window function would cover the two subselects - at least, I'm
fairly sure it would. I can't quite get the whole thing, though; I can
get a true/false flag that says whether it's near to the previous one
(that's easy), and creating a grouping column value should be possible
from that but I'm not sure how.
But an either-or grouping is a bit trickier. The best I can think of
is to collect all the y values for each group of x values, and then if
any two groups 'overlap' (ie have points within 1.0 of each other),
merge the groups. That's going to be seriously tricky to do in SQL, I
think, so you may have to go back to Python on that one.
My analysis suggests that, whatever happens, you're going to need
every single y value somewhere. So it's probably not worth trying to
do any grouping/aggregation in SQL, since you need to further analyze
all the individual data points. I can't think of any way better than
just leafing through the whole table (either in Python or in a stored
procedure - if you can run your script on the same computer that's
running the database, I'd do that, otherwise consider a stored
procedure to reduce network transfers) and building up mappings.
Of course, "I can't think of a way" does not equate to "There is no
way". There may be some magic trick that I didn't think of, or some
arcane incantation that gets what you want. Who knows? If you can
produce an ASCII art Mandelbrot set [1] in pure SQL, why not this!
ChrisA
[1] http://wiki.postgresql.org/wiki/Mandelbrot_set
== 5 of 9 ==
Date: Sun, Jan 12 2014 7:17 pm
From: Larry Martell
On Sun, Jan 12, 2014 at 2:53 PM, Petite Abeille
<petite.abeille@gmail.com> wrote:
>
> On Jan 12, 2014, at 8:23 PM, Larry Martell <larry.martell@gmail.com> wrote:
>
>> AFAIK, there is no way to do this in SQL.
>
> Sounds like a job for window functions (aka analytic functions) [1][2].
>
> [1] http://www.postgresql.org/docs/9.3/static/tutorial-window.html
> [2] http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions004.htm#SQLRF06174
Unfortunately, MySQL does not support this.
== 6 of 9 ==
Date: Sun, Jan 12 2014 7:18 pm
From: Larry Martell
On Sun, Jan 12, 2014 at 5:18 PM, Chris Angelico <rosuav@gmail.com> wrote:
> On Mon, Jan 13, 2014 at 6:53 AM, Petite Abeille
> <petite.abeille@gmail.com> wrote:
>> On Jan 12, 2014, at 8:23 PM, Larry Martell <larry.martell@gmail.com> wrote:
>>
>>> AFAIK, there is no way to do this in SQL.
>>
>> Sounds like a job for window functions (aka analytic functions) [1][2].
>
> That's my thought too. I don't think MySQL has them, though, so it's
> either going to have to be done in Python, or the database back-end
> will need to change. Hard to say which would be harder.
Changing the database is not feasible.
== 7 of 9 ==
Date: Sun, Jan 12 2014 7:25 pm
From: Larry Martell
On Sun, Jan 12, 2014 at 5:43 PM, Dennis Lee Bieber
<wlfraed@ix.netcom.com> wrote:
> On Sun, 12 Jan 2014 14:23:17 -0500, Larry Martell <larry.martell@gmail.com>
> declaimed the following:
>
>>I have an python app that queries a MySQL DB. The query has this form:
>>
>>SELECT a, b, c, d, AVG(e), STD(e), CONCAT(x, ',', y) as f
>>FROM t
>>GROUP BY a, b, c, d, f
>>
>>x and y are numbers (378.18, 2213.797 or 378.218, 2213.949 or
>>10053.490, 2542.094).
>>
>
> Decimal (Numeric) or floating/real. If the latter, the internal storage
> may not be exact (378.1811111111 and 378.179999999 may both "display" as
> 378.18, but will not match for grouping).
In the database they are decimal. They are being converted to char by
the CONCAT(x, ',', y).
>>The business issue is that if either x or y in 2 rows that are in the
>>same a, b, c, d group are within 1 of each other then they should be
>>grouped together. And to make it more complicated, the tolerance is
>>applied as a rolling continuum. For example, if the x and y in a set
>>of grouped rows are:
>>
> As I understand group by, it will first group by "a", WITHIN the "a"
> groups it will then group by "b"... Probably not a matter germane to the
> problem as you are concerning yourself with the STRING representation of
> "x" and "y" with a comma delimiter -- which is only looked at if the
> "a,b,c,d" are equal... Thing is, a string comparison is going to operate
> strictly left to right -- it won't even see your "y" value unless all the
> "x" value is equal.
Yes, that is correct. The original requirement was to group by (X, Y),
so the CONCAT(x, ',', y) was correct and working. Then the requirement
was change to apply the tolerance as I described.
>
> You may need to operate using subselects... So that you can specify
> something like
>
> where abs(s1.x -s2.x) < tolerance or abs(s1.y-s2.y) < tolerance
> and (s1.a = s2.a ... s1.d = s2.d)
>
> s1/s1 are the subselects (you may need a primary key <> primary key to
> avoid having it output a record where the two subselects are for the SAME
> record -- or maybe not, since you /do/ want that record also output). Going
> to be a costly query since you are basically doing
>
> foreach r1 in s1
> foreach r2 in s2
> emit r2 when...
Speed is an issue here, and while the current query performs well, in
my experience subqueries and self joins do not. I'm going to try and
do it all in python and see how it performs. The other option is to
pre-process the data on the way into the database. Doing that will
eliminate some of the data partitioning as all of the data that could
be joined will be in the same input file. I'm just not sure if it will
OK to actually munge the data. I'll find that out tomorrow.
== 8 of 9 ==
Date: Sun, Jan 12 2014 7:35 pm
From: Larry Martell
On Sun, Jan 12, 2014 at 6:27 PM, Chris Angelico <rosuav@gmail.com> wrote:
> On Mon, Jan 13, 2014 at 6:23 AM, Larry Martell <larry.martell@gmail.com> wrote:
>> I have an python app that queries a MySQL DB. The query has this form:
>>
>> SELECT a, b, c, d, AVG(e), STD(e), CONCAT(x, ',', y) as f
>> FROM t
>> GROUP BY a, b, c, d, f
>>
>> x and y are numbers (378.18, 2213.797 or 378.218, 2213.949 or
>> 10053.490, 2542.094).
>>
>> The business issue is that if either x or y in 2 rows that are in the
>> same a, b, c, d group are within 1 of each other then they should be
>> grouped together. And to make it more complicated, the tolerance is
>> applied as a rolling continuum. For example, if the x and y in a set
>> of grouped rows are:
>>
>> row 1: 1.5, 9.5
>> row 2: 2.4, 20.8
>> row 3: 3.3, 40.6
>> row 4: 4.2, 2.5
>> row 5: 5.1, 10.1
>> row 6: 6.0, 7.9
>> row 7: 8.0, 21.0
>> row 8: 100, 200
>>
>> 1 through 6 get combined because all their X values are within the
>> tolerance of some other X in the set that's been combined. 7's Y value
>> is within the tolerance of 2's Y, so that should be combined as well.
>> 8 is not combined because neither the X or Y value is within the
>> tolerance of any X or Y in the set that was combined.
>
> Trying to get my head around this a bit more. Are columns a/b/c/d
> treated as a big category (eg type, brand, category, model), such that
> nothing will ever be grouped that has any difference in those four
> columns? If so, we can effectively ignore them and pretend we have a
> table with exactly one set (eg stick a WHERE clause onto the query
> that stipulates their values). Then what you have is this:
>
> * Aggregate based on proximity of x and y
> * Emit results derived from e
>
> Is that correct?
There will be multiple groups of a/b/c/d. I simplified the query for
the purposes of posting my question. There is a where clause with
values that come from user input. None, any, or all of a, b, c, or d
could be in the where clause.
> So here's my way of writing it.
>
> * Subselect: List all values for x, in order, and figure out which
> ones are less than the previous value plus one
> * Subselect: Ditto, for y.
> * Outer select: Somehow do an either-or group. I'm not quite sure how
> to do that part, actually!
>
> A PGSQL window function would cover the two subselects - at least, I'm
> fairly sure it would. I can't quite get the whole thing, though; I can
> get a true/false flag that says whether it's near to the previous one
> (that's easy), and creating a grouping column value should be possible
> from that but I'm not sure how.
>
> But an either-or grouping is a bit trickier. The best I can think of
> is to collect all the y values for each group of x values, and then if
> any two groups 'overlap' (ie have points within 1.0 of each other),
> merge the groups. That's going to be seriously tricky to do in SQL, I
> think, so you may have to go back to Python on that one.
>
> My analysis suggests that, whatever happens, you're going to need
> every single y value somewhere. So it's probably not worth trying to
> do any grouping/aggregation in SQL, since you need to further analyze
> all the individual data points. I can't think of any way better than
> just leafing through the whole table (either in Python or in a stored
> procedure - if you can run your script on the same computer that's
> running the database, I'd do that, otherwise consider a stored
> procedure to reduce network transfers) and building up mappings.
>
> Of course, "I can't think of a way" does not equate to "There is no
> way". There may be some magic trick that I didn't think of, or some
> arcane incantation that gets what you want. Who knows? If you can
> produce an ASCII art Mandelbrot set [1] in pure SQL, why not this!
>
> ChrisA
>
> [1] http://wiki.postgresql.org/wiki/Mandelbrot_set
Thanks for the reply. I'm going to take a stab at removing the group
by and doing it all in python. It doesn't look too hard, but I don't
know how it will perform.
== 9 of 9 ==
Date: Sun, Jan 12 2014 10:09 pm
From: Chris Angelico
On Mon, Jan 13, 2014 at 2:35 PM, Larry Martell <larry.martell@gmail.com> wrote:
> Thanks for the reply. I'm going to take a stab at removing the group
> by and doing it all in python. It doesn't look too hard, but I don't
> know how it will perform.
Well, if you can't switch to PostgreSQL or such, then doing it in
Python is your only option. There are such things as GiST and GIN
indexes that might be able to do some of this magic, but I don't think
MySQL has anything even remotely like what you're looking for.
So ultimately, you're going to have to do your filtering on the
database, and then all the aggregation in Python. And it's going to be
somewhat complicated code, too. Best I can think of is this, as
partial pseudo-code:
last_x = -999
x_map = []; y_map = {}
merge_me = []
for x,y,e in (SELECT x,y,e FROM t WHERE whatever ORDER BY x):
if x<last_x+1:
x_map[-1].append((y,e))
else:
x_map.append([(y,e)])
last_x=x
if y in y_map:
merge_me.append((y_map[y], x_map[-1]))
y_map[y]=x_map[-1]
# At this point, you have x_map which is a list of lists, each one
# being one group, and y_map which maps a y value to its x_map list.
last_y = -999
for y in sorted(y_map.keys()):
if y<last_y+1:
merge_me.append((y_map[y], last_x_map))
last_y=y
last_x_map=y_map[y]
for merge1,merge2 in merge_me:
merge1.extend(merge2)
merge2[:]=[] # Empty out the list
for lst in x_map:
if not lst: continue # been emptied out, ignore it
do aggregate stats, get sum(lst) and whatever else
I think this should be linear complexity overall, but there may be a
few aspects of it that are quadratic. It's a tad messy though, and
completely untested. But that's an algorithmic start. The idea is that
lists get collected based on x proximity, and then lists get merged
based on y proximity. That is, if you have (1.0, 10.1), (1.5, 2.3),
(3.0, 11.0), (3.2, 15.2), they'll all be treated as a single
aggregation unit. If that's not what you want, I'm not sure how to
handle it.
ChrisA
==============================================================================
TOPIC: Problem writing some strings (UnicodeEncodeError)
http://groups.google.com/group/comp.lang.python/t/08d2e6a4bc11d1c3?hl=en
==============================================================================
== 1 of 4 ==
Date: Sun, Jan 12 2014 12:29 pm
From: Peter Otten <__peter__@web.de>
Paulo da Silva wrote:
>> but I have not tried it myself. Also, some bytes may need to be escaped,
>> either to be understood by the shell, or to address security concerns:
>>
>
> Since I am puting the file names between "", the only char that needs to
> be escaped is the " itself.
What about the escape char?
== 2 of 4 ==
Date: Sun, Jan 12 2014 3:53 pm
From: Paulo da Silva
Em 12-01-2014 20:29, Peter Otten escreveu:
> Paulo da Silva wrote:
>
>>> but I have not tried it myself. Also, some bytes may need to be escaped,
>>> either to be understood by the shell, or to address security concerns:
>>>
>>
>> Since I am puting the file names between "", the only char that needs to
>> be escaped is the " itself.
>
> What about the escape char?
>
Just this fn=fn.replace('"','\\"')
So far I didn't find any problem, but the script is still running.
== 3 of 4 ==
Date: Mon, Jan 13 2014 12:48 am
From: Peter Otten <__peter__@web.de>
Paulo da Silva wrote:
> Em 12-01-2014 20:29, Peter Otten escreveu:
>> Paulo da Silva wrote:
>>
>>>> but I have not tried it myself. Also, some bytes may need to be
>>>> escaped, either to be understood by the shell, or to address security
>>>> concerns:
>>>>
>>>
>>> Since I am puting the file names between "", the only char that needs to
>>> be escaped is the " itself.
>>
>> What about the escape char?
>>
> Just this fn=fn.replace('"','\\"')
>
> So far I didn't find any problem, but the script is still running.
To be a bit more explicit:
>>> for filename in os.listdir():
... print(template.replace("<fn>", filename.replace('"', '\\"')))
...
ls "\\"; rm whatever; ls \"
== 4 of 4 ==
Date: Mon, Jan 13 2014 12:58 am
From: Peter Otten <__peter__@web.de>
Peter Otten wrote:
> Paulo da Silva wrote:
>
>> Em 12-01-2014 20:29, Peter Otten escreveu:
>>> Paulo da Silva wrote:
>>>
>>>>> but I have not tried it myself. Also, some bytes may need to be
>>>>> escaped, either to be understood by the shell, or to address security
>>>>> concerns:
>>>>>
>>>>
>>>> Since I am puting the file names between "", the only char that needs
>>>> to be escaped is the " itself.
>>>
>>> What about the escape char?
>>>
>> Just this fn=fn.replace('"','\\"')
>>
>> So far I didn't find any problem, but the script is still running.
>
> To be a bit more explicit:
>
>>>> for filename in os.listdir():
> ... print(template.replace("<fn>", filename.replace('"', '\\"')))
> ...
> ls "\\"; rm whatever; ls \"
The complete session:
>>> import os
>>> template = 'ls "<fn>"'
>>> with open('\\"; rm whatever; ls \\', "w") as f: pass
...
>>> for filename in os.listdir():
... print(template.replace("<fn>", filename.replace('"', '\\"')))
...
ls "\\"; rm whatever; ls \"
Shell variable substitution is another problem. c.l.py is probably not the
best place to get the complete list of possibilities.
==============================================================================
TOPIC: Python: 404 Error when trying to login a webpage by using 'urllib' and
'HTTPCookieProcessor'
http://groups.google.com/group/comp.lang.python/t/bf0e28e020a02c69?hl=en
==============================================================================
== 1 of 1 ==
Date: Sun, Jan 12 2014 12:51 pm
From: Terry Reedy
On 1/12/2014 7:17 AM, KMeans Algorithm wrote:
> But I get a "404" error (Not Found). The page "https://www.mysite.com/loginpage" does exist
Firefox tells me the same thing. If that is a phony address, you should
have said so.
--
Terry Jan Reedy
==============================================================================
TOPIC: Python example source code
http://groups.google.com/group/comp.lang.python/t/8594472fa123f77e?hl=en
==============================================================================
== 1 of 1 ==
Date: Sun, Jan 12 2014 3:16 pm
From: Denis McMahon
On Sun, 12 Jan 2014 06:37:18 -0800, ngangsia akumbo wrote:
> where can i find example source code by topic?
> Any help please
You don't want to be looking at source code yet, you want to be talking
to the users of the system you're trying to design to find out what their
requirements are.
--
Denis McMahon, denismfmcmahon@gmail.com
==============================================================================
TOPIC: extracting string.Template substitution placeholders
http://groups.google.com/group/comp.lang.python/t/e98ada5213c4b344?hl=en
==============================================================================
== 1 of 1 ==
Date: Sun, Jan 12 2014 11:24 pm
From: Steven D'Aprano
On Sun, 12 Jan 2014 10:08:31 -0500, Eric S. Johansson wrote:
> As part of speech recognition accessibility tools that I'm building, I'm
> using string.Template. In order to construct on-the-fly grammar, I need
> to know all of the identifiers before the template is filled in. what is
> the best way to do this?
py> import string
py> t = string.Template("$sub some $text $here")
py> t.template
'$sub some $text $here'
Now just walk the template for $ signs. Watch out for $$ which escapes
the dollar sign. Here's a baby parser:
def get_next(text, start=0):
while True:
i = text.find("$", start)
if i == -1:
return
if text[i:i+2] == '$$':
start += i
continue
j = text.find(' ', i)
if j == -1:
j = len(text)
assert i < j
return (text[i:j], j)
start = 0
while start < len(t.template):
word, start = get_next(t.template, start)
print(word)
> can string.Template handle recursive expansion i.e. an identifier
> contains a template.
If you mean, recursive expand the template until there's nothing left to
substitute, then no, not directly. You would have to manually expand the
template yourself.
--
Steven
==============================================================================
TOPIC: plotting slows down
http://groups.google.com/group/comp.lang.python/t/22f280b151f3c221?hl=en
==============================================================================
== 1 of 2 ==
Date: Mon, Jan 13 2014 12:15 am
From: norman.elliott@gmail.com
First let me say I have not done much python programming!
I am running Python 2.7.3.
I am trying to use python as a front end to a simple oscilloscope.
Ultimately I intend to use it with my micropython board.
At the moment I am just developing it. All it does is use a module I found called graphics.py to create a window and display randomly generated data.
Each time it goes through the outer loop it gets slower and slower.
I put in a small delay just so I could observe what is happening and for the first line it draws it takes about a second. If I set it to loop 20 times the final loop takes more than 6 seconds.
Can anyone explain what I am doing wrong please?
Here is the code:
[code]
#!/usr/bin/python
from graphics import *
import random
import time
xpos=1200
ypos=400
ypnt=ypos/2
pos=1
#setBackground("white")
def main():
win = GraphWin("My Circle", xpos, ypos)
# win.setBackGround('white')
for y in range(1,5):
cir2 = Circle(Point(xpos/2,20), 10)
cir2.setFill("white")
cir2.draw(win)
message = Text(Point(win.getWidth()/2, 20), y)
message.draw(win)
j = random.randint(1,ypos)
for x in range(1,xpos):
updown = random.randint(0,1)
if updown:
j=j+1
else:
j=j-1
if j <1:
j=ypos/2
if j>ypos-1:
j=ypos/2
win.plot(x,j,"red")
time.sleep(.0001)
main()
time.sleep(5)
[/code]
== 2 of 2 ==
Date: Mon, Jan 13 2014 5:26 am
From: Dave Angel
norman.elliott@gmail.com Wrote in message:
> First let me say I have not done much python programming!
> I am running Python 2.7.3.
> I am trying to use python as a front end to a simple oscilloscope.
> Ultimately I intend to use it with my micropython board.
>
> At the moment I am just developing it. All it does is use a module I found called graphics.py to create a window and display randomly generated data.
>
> Each time it goes through the outer loop it gets slower and slower.
> I put in a small delay just so I could observe what is happening and for the first line it draws it takes about a second. If I set it to loop 20 times the final loop takes more than 6 seconds.
> Can anyone explain what I am doing wrong please?
> Here is the code:
> [code]
> #!/usr/bin/python
> from graphics import *
First things first. what operating system are you using, and
where did you get the mysterious graphics. py? Thanks for
telling us python 2.7.3
Next, please repost any source code with indentation preserved.
Your message shows it all flushed to the left margin, probably
due to posting in html mode. Use text mode here.
Finally, since you seem to be using googlegroups, please make
sure you don't double space your quotes. See. wiki.python.org/moi
n/GoogleGroupsPython
>
--
DaveA
----Android NewsGroup Reader----
http://www.piaohong.tk/newsgroup
==============================================================================
TOPIC: 'Straße' ('Strasse') and Python 2
http://groups.google.com/group/comp.lang.python/t/93ddbbff468ab95d?hl=en
==============================================================================
== 1 of 5 ==
Date: Mon, Jan 13 2014 12:27 am
From: Thomas Rachel
Am 12.01.2014 08:50 schrieb wxjmfauth@gmail.com:
>>>> sys.version
> 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]
>>>> s = 'Stra�e'
>>>> assert len(s) == 6
>>>> assert s[5] == 'e'
>>>>
Wow. You just found one of the major differences between Python 2 and 3.
Your assertins are just wrong, as s = 'Stra�e' leads - provided you use
UTF8 - to a representation of 'Stra\xc3\x9fe', obviously leading to a
length of 7.
Thomas
== 2 of 5 ==
Date: Mon, Jan 13 2014 1:54 am
From: wxjmfauth@gmail.com
Le lundi 13 janvier 2014 09:27:46 UTC+1, Thomas Rachel a écrit :
> Am 12.01.2014 08:50 schrieb wxjmfauth@gmail.com:
>
> >>>> sys.version
>
> > 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]
>
> >>>> s = 'Stra�e'
>
> >>>> assert len(s) == 6
>
> >>>> assert s[5] == 'e'
>
> >>>>
>
>
>
> Wow. You just found one of the major differences between Python 2 and 3.
>
>
>
> Your assertins are just wrong, as s = 'Stra�e' leads - provided you use
>
> UTF8 - to a representation of 'Stra\xc3\x9fe', obviously leading to a
>
> length of 7.
>
>
Not at all. I'm afraid I'm understanding Python (on this
aspect very well).
Do you belong to this group of people who are naively
writing wrong Python code (usually not properly working)
during more than a decade?
'ß' is the the fourth character in that text "Straße"
(base index 0).
This assertions are correct (byte string and unicode).
>>> sys.version
'2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]'
>>> assert 'Straße'[4] == 'ß'
>>> assert u'Straße'[4] == u'ß'
>>>
jmf
PS Nothing to do with Py2/Py3.
== 3 of 5 ==
Date: Mon, Jan 13 2014 2:26 am
From: Chris Angelico
On Mon, Jan 13, 2014 at 8:54 PM, <wxjmfauth@gmail.com> wrote:
> This assertions are correct (byte string and unicode).
>
>>>> sys.version
> '2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]'
>>>> assert 'Straße'[4] == 'ß'
>>>> assert u'Straße'[4] == u'ß'
>>>>
>
> jmf
>
> PS Nothing to do with Py2/Py3.
This means that either your source encoding happens to include that
character, or you have assertions disabled. It does NOT mean that you
can rely on writing this string out to a file and having someone else
read it in and understand it the same way.
ChrisA
== 4 of 5 ==
Date: Mon, Jan 13 2014 2:38 am
From: Steven D'Aprano
On Mon, 13 Jan 2014 01:54:21 -0800, wxjmfauth wrote:
>>>> sys.version
> '2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]'
>>>> assert 'Straße'[4] == 'ß'
>>>> assert u'Straße'[4] == u'ß'
I think you are using "from __future__ import unicode_literals".
Otherwise, that cannot happen in Python 2.x. Using a narrow build:
# on my machine "ando"
py> sys.version
'2.7.2 (default, May 18 2012, 18:25:10) \n[GCC 4.1.2 20080704 (Red Hat
4.1.2-52)]'
py> sys.maxunicode
65535
py> assert 'Straße'[4] == 'ß'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AssertionError
py> list('Straße')
['S', 't', 'r', 'a', '\xc3', '\x9f', 'e']
Using a wide build is the same:
# on my machine "orac"
>>> sys.maxunicode
1114111
>>> assert 'Straße'[4] == 'ß'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AssertionError
But once you run the "from __future__" line, the behaviour changes to
what you show:
py> from __future__ import unicode_literals
py> list('Straße')
[u'S', u't', u'r', u'a', u'\xdf', u'e']
py> assert 'Straße'[4] == 'ß'
py>
But I still don't understand the point you are trying to make.
--
Steven
== 5 of 5 ==
Date: Mon, Jan 13 2014 2:57 am
From: Chris Angelico
On Mon, Jan 13, 2014 at 9:38 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> I think you are using "from __future__ import unicode_literals".
> Otherwise, that cannot happen in Python 2.x.
>
Alas, not true.
>>> sys.version
'2.7.4 (default, Apr 6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)]'
>>> sys.maxunicode
65535
>>> assert 'Straße'[4] == 'ß'
>>> list('Straße')
['S', 't', 'r', 'a', '\xdf', 'e']
That's Windows XP. Presumably Latin-1 (or CP-1252, they both have that
char at 0xDF). He happens to be correct, *as long as the source code
encoding matches the output encoding and is one that uses 0xDF to mean
U+00DF*. Otherwise, he's not.
ChrisA
==============================================================================
TOPIC: L[:]
http://groups.google.com/group/comp.lang.python/t/8c4883bbe077624c?hl=en
==============================================================================
== 1 of 1 ==
Date: Mon, Jan 13 2014 1:00 am
From: Laszlo Nagy
> Unless L is aliased, this is silly code.
There is another use case. If you intend to modify a list within a for
loop that goes over the same list, then you need to iterate over a copy.
And this cannot be called an "alias" because it has no name:
for idx,item in enumerate(L[:]):
# do something with L here, including modification
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
==============================================================================
TOPIC: Module depositary
http://groups.google.com/group/comp.lang.python/t/98da54fb4adeccb4?hl=en
==============================================================================
== 1 of 2 ==
Date: Mon, Jan 13 2014 2:05 am
From: Sean Murphy
Hi All.
I am aware that active state python has a commercial module depositary which you can get modules from. Under PERL you had CPAN. Is there anything like this for Python?
Sean
== 2 of 2 ==
Date: Mon, Jan 13 2014 2:24 am
From: Chris Angelico
On Mon, Jan 13, 2014 at 9:05 PM, Sean Murphy <mhysnm1964@gmail.com> wrote:
> Hi All.
>
> I am aware that active state python has a commercial module depositary which you can get modules from. Under PERL you had CPAN. Is there anything like this for Python?
Check out the Python Package Index:
https://pypi.python.org/pypi
It's not commercial, and (as far as I know) there's no curating of
projects, so you need to make your own decision about what you trust
and how you handle version dependencies. There are easy and convenient
ways to install packages, most notably pip (which is mentioned on the
landing page).
ChrisA
==============================================================================
You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.
To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en
To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com
To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en
To report abuse, send email explaining the problem to abuse@googlegroups.com
==============================================================================
Google Groups: http://groups.google.com/?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home