Re: Printing a drop down menu for a specific field.

2013-10-21 Thread Steven D'Aprano
On Mon, 21 Oct 2013 09:07:17 +0300, Νίκος Αλεξόπουλος wrote:

>>  for row in data:
>>  (host, city, useros, browser, ref, hits, lastvisit) = row
>>  lastvisit = lastvisit.strftime('%A %e %b, %H:%M')
>>
>>  print( "" )
>>  for item in (host, city, useros, browser, ref, hits,
>>  lastvisit):
>>  print( " %s " % item
>>  )
[...]
>> In the above code i print the record of the mysql table visitors in
>> each row like this:  http://superhost.gr/?show=log&page=index.html
>>
>> Now, i wish to write the same thing but when it comes to print the
>> 'lastvisit' field to display it in a  tag so all prior
>> visits for the same host appear in a drop down menu opposed to as i
>> have it now which i only print the datetime of just the latest visit of
>> that host and not all its visit datetimes.
>>
>> I hope i made it clear what i want to achieve.
> 
> 
> Any help would be appreciated.


Step 1:

Decide what counts as "the same visitor". Is it...?

- anyone with the same IP address?
- anyone with the same IP address and the same useros?
- anyone with the same IP address, the same useros, and the same browser?
- something else?


Step 2:

Scan the data, pulling out the record of the same unique visitor, and 
collecting the dates for that record. For example, you might write code 
like this:

# Untested, probably buggy.
visitors = []
records = []
for row in data:
host, city, useros, browser, ref, hits, lastvisit = row
if (host, ref) in visitors:
# Seen this visitor before. Add the date to that record.
record_no = visitors.index((host, ref))
else:
# New visitor, never seen before!
visitors.append((host, ref))
records.append([])
record_no = len(visitors)
records[record_no].append(lastvisit)


There may be more efficient ways to do the same thing, if you can think 
of a way to associate a list of values with a visitor key.

However you do it, by the time you have finished, you'll have a list of 
unique visitors, and a corresponding list containing the date of each of 
their visits. 

Step 3: When you go to build the table:

- identify which unique visitor this record represents
- look up the list of dates from that record
- build a  menu from that list of dates
- insert the menu into the table


and you're done.



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


Re: Python was designed (was Re: Multi-threading in Python vs Java)

2013-10-21 Thread Chris Angelico
On Mon, Oct 21, 2013 at 5:44 PM, Peter Cacioppi
 wrote:
> I've written a fair bit of code in pure C, C++, C#, Java and now getting 
> there in Python.
>
> The difference between C# and Java is fairly minor.
>
> The others have large and significant differences between them. Garbage 
> collectors or not is huge. Exceptions or not is huge.  Dynamic or static 
> typing is huge. Language support for polymorphism or not is huge.
>
> This is just one language feature. I could go on and on. The idea that the 
> differences between these languages is just syntactic sugar and aesthetics is 
> so profoundly misguided that I can only assume that this misconception was 
> proposed as a bizarre form of trolling.

I don't think anyone's denying that there are differences. If there
weren't, we'd all be using the same language! But most of what you
said isn't object orientation. Garbage collection is huge, but it's
nothing to do with OOP. Exceptions are completely separate again. (And
exception *usage* is separate from exceptions. C++ and PHP both
support exceptions, but most operations don't raise them. Python, on
the other hand, uses exceptions for everything.)

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


Re: skipping __init__ and using exploiting a class member instead

2013-10-21 Thread feedthetroll
Am Montag, 21. Oktober 2013 06:31:36 UTC+2 schrieb Peter Cacioppi:
> That sound you hear is Roy Smith hitting the nail on the head.

PLONK: The sound you hear, when a context-less troll is hitting the bottom of 
my killfile.
-- 
https://mail.python.org/mailman/listinfo/python-list


Animated PNG Vs Gif: 120fr 3D Python Powered Logo

2013-10-21 Thread Metallicow
Discussion:

Dear Guido and friends,

Noticed this is gaining alot more support lately.
http://www.kickstarter.com/projects/374397522/apngasm-foss-animated-png-tools-and-apng-standardi

After testing my gif and apng Animated 3D Python Powered Logos...
The difference is real obvious at first. apng wins with speed(gif is limited to 
say 1/10sec and apng can do at least 1/80sec) and transparency/color 
quality(tested on windows ATM)

Mozilla based browsers, Opera, Chrome(extension), Xnview and some other popular 
apps have integrated rendering apng functionality so far...
I wouldn't tend to think that the top browser devs were wrong in their choice.
It would be nice to receive the Guido *nod of approval*... attached samples are 
under PSF License or your better suggestion, BDFL.

Hopefully there will be a libpng implementation and pyAPNG stuff(s) worked on 
also soon.

Attachments:
Animated Python Powered Logo - 120 frames
1. gif format
2. apng format(if it doesn't animate in your browser, then apng is not 
supported yet)

If you like what you see, then consider supporting the devs working on this and 
help make it a standard or start devving yourselves.

@pyDEVs: Any news on this yet...?

Python Samples Downloads available:
Animated Python Powered Logo - 120 frames
1 gif & 1 apng samples in download.
http://www.4shared.com/archive/MzoW-0Kt/AnimatedPythonPoweredLogoGifVs.html

I can't seem to attach a file in this group, thus the waiting DL. Apparently, i 
am not qualified enough or something here(at least on this group)..., but then 
again if every python fanatic that posts spam here did the same, then the world 
would turn into eggs.

Your welcome. Python is the Best! 

Comments, complaints, spam, eggs, etc., welcome here also.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python was designed (was Re: Multi-threading in Python vs Java)

2013-10-21 Thread Mark Lawrence

On 21/10/2013 07:44, Peter Cacioppi wrote:

I've written a fair bit of code in pure C, C++, C#, Java and now getting there 
in Python.

The difference between C# and Java is fairly minor.

The others have large and significant differences between them. Garbage 
collectors or not is huge. Exceptions or not is huge.  Dynamic or static typing 
is huge. Language support for polymorphism or not is huge.

C code invokes a very meaningful overhead of memory management. The task of 
insuring that memory doesn't leak here is far larger than in garbage collected 
languages, and much more difficult than C++ (which can guarantee stack based 
destruction).

This is just one language feature. I could go on and on. The idea that the 
differences between these languages is just syntactic sugar and aesthetics is 
so profoundly misguided that I can only assume that this misconception was 
proposed as a bizarre form of trolling.




As my crystal ball is once again being mended, would you please be kind 
enough to tell all of us who and exactly what you're replying to.


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Python was designed (was Re: Multi-threading in Python vs Java)

2013-10-21 Thread Chris Angelico
On Mon, Oct 21, 2013 at 6:27 PM, Mark Lawrence  wrote:
> On 21/10/2013 07:44, Peter Cacioppi wrote:
>> [ a whole lot of stuff ]
>
> As my crystal ball is once again being mended, would you please be kind
> enough to tell all of us who and exactly what you're replying to.

Mine is in service at the moment. It says that Peter was actually trying to say:

"I use Google Groups and it sucks, so I delete all the context because
then nobody can see how much it sucks at showing context."

Peter, please can you use a different posting method? GG doesn't wrap
text properly, so it often results in really long lines with only a
single angle-bracket marking it as a quote, which makes the _next_
level of citation ugly.

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


Re: Printing a drop down menu for a specific field.

2013-10-21 Thread Mark Lawrence

On 21/10/2013 07:07, Νίκος Αλεξόπουλος wrote:


Any help would be appreciated.


It is considered polite to wait for at least 24 hours before pinging. 
If waiting for this time isn't an option then paying for support is.


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Printing a drop down menu for a specific field.

2013-10-21 Thread Νίκος Αλεξόπουλος

Στις 21/10/2013 9:58 πμ, ο/η Steven D'Aprano έγραψε:

On Mon, 21 Oct 2013 09:07:17 +0300, Νίκος Αλεξόπουλος wrote:


  for row in data:
  (host, city, useros, browser, ref, hits, lastvisit) = row
  lastvisit = lastvisit.strftime('%A %e %b, %H:%M')

  print( "" )
  for item in (host, city, useros, browser, ref, hits,
  lastvisit):
  print( " %s " % item
  )

[...]

In the above code i print the record of the mysql table visitors in
each row like this:  http://superhost.gr/?show=log&page=index.html

Now, i wish to write the same thing but when it comes to print the
'lastvisit' field to display it in a  tag so all prior
visits for the same host appear in a drop down menu opposed to as i
have it now which i only print the datetime of just the latest visit of
that host and not all its visit datetimes.

I hope i made it clear what i want to achieve.



Any help would be appreciated.



Step 1:

Decide what counts as "the same visitor". Is it...?

- anyone with the same IP address?
- anyone with the same IP address and the same useros?
- anyone with the same IP address, the same useros, and the same browser?
- something else?


First let me show you the database insertion to start form there:

The definition of the same visitor in my case is basically a combination 
of they page the visitor tries to visit along with its hostname. At 
MySQL's definition iam implementing this as:


  unique index (counterID, host)


Up until now i was updating the record of the same visitor as follows:


# if first time visitor on this page, create new record, if visitor 
exists then update record
cur.execute('''INSERT INTO visitors (counterID, host, city, useros, 
browser, ref, lastvisit) VALUES (%s, %s, %s, %s, %s, %s, %s)
		ON DUPLICATE KEY UPDATE city = %s, useros = %s, browser = %s, ref = 
%s, hits = hits + 1, lastvisit = %s''',
	(cID, host, city, useros, browser, ref, lastvisit, city, useros, 
browser, ref, lastvisit) )

=


Since now i have decided to have more records for the same visitor if 
i'm gonna save its history of visits, i'm thinking that i can no longer 
update the same unique visitor record but save many records related to 
the same visitor. so i use this:



=
# ~ DATABASE INSERTS ~
=
try:
	# if first time for webpage; create new record( primary key is 
automatic, hit is defaulted ), if page exists then update record
	cur.execute('''INSERT INTO counters (url) VALUES (%s) ON DUPLICATE KEY 
UPDATE hits = hits + 1''', page )

# get the primary key value of the new added record
cID = cur.lastrowid

	# if first time visitor on this page, create new record, if visitor 
exists then update record
	cur.execute('''INSERT INTO visitors (counterID, host, city, useros, 
browser, ref, lastvisit) VALUES (%s, %s, %s, %s, %s, %s, %s)''',

   (cID, host, city, useros, browser, 
ref, lastvisit) )

con.commit()
except pymysql.ProgrammingError as e:
print( repr(e) )
con.rollback()
=


Are we good up until this point as it concerns the database insertions?
If we are then we can discuss how to present the saved data.


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


Re: Python was designed (was Re: Multi-threading in Python vs Java)

2013-10-21 Thread Mark Lawrence

On 21/10/2013 08:31, Chris Angelico wrote:


"I use Google Groups and it sucks, so I delete all the context because
then nobody can see how much it sucks at showing context."


Because it's written in (say) C++ in an object orientated style, so by 
rewriting it using assembler in a procedural style it will be fixed?




ChrisA



--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Python was designed (was Re: Multi-threading in Python vs Java)

2013-10-21 Thread Chris Angelico
On Mon, Oct 21, 2013 at 6:39 PM, Mark Lawrence  wrote:
> On 21/10/2013 08:31, Chris Angelico wrote:
>
>> "I use Google Groups and it sucks, so I delete all the context because
>> then nobody can see how much it sucks at showing context."
>
>
> Because it's written in (say) C++ in an object orientated style, so by
> rewriting it using assembler in a procedural style it will be fixed?

Certainly not. The solution is to use FORTRAN and functional style.
That should be obvious!

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


Re: Python Front-end to GCC

2013-10-21 Thread Steven D'Aprano
On Sun, 20 Oct 2013 20:35:03 -0700, Mark Janssen wrote:

[Attribution to the original post has been lost]
>> Is a jit implementation of a language (not just python) better than
>> traditional ahead of time compilation.
> 
> Not at all.  The value of jit compilation, I believe, is purely for the
> dynamic functionality that it allows.  AOT compilation will never allow
> that, but in return you get massive performance and runtime-size gains

On the contrary, you have that backwards. An optimizing JIT compiler can 
often produce much more efficient, heavily optimized code than a static 
AOT compiler, and at the very least they can optimize different things 
than a static compiler can. This is why very few people think that, in 
the long run, Nuitka can be as fast as PyPy, and why PyPy's ultimate aim 
to be "faster than C" is not moonbeams:

http://morepypy.blogspot.com.au/2011/02/pypy-faster-than-c-on-carefully-crafted.html

http://morepypy.blogspot.com.au/2011/08/pypy-is-faster-than-c-again-string.html


See here for a discussion on what JIT compilers can do which static 
compilers can't:

http://en.wikipedia.org/wiki/Just-in-time_compilation


Of course, the disadvantage of a JIT compiler is that there's a certain 
amount of runtime overhead: it takes time to analyse the running code, 
and more time to compile it on the fly. This is why, for example, PyPy 
likely won't be as fast for really short-running scripts as a static 
compiler could be. Again, see the Wikipedia article.

JIT compilation is really about optimization, which is why languages like 
Java and .NET which could easily be compiled to machine code at compile 
time generally use an intermediate bytecode and a JIT compiler instead. 
They're not doing it for dynamism since they aren't dynamic languages. 
It's a way of generating more aggressive (i.e. better but harder) 
optimizations based on information only available at runtime.



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


Re: Python was designed (was Re: Multi-threading in Python vs Java)

2013-10-21 Thread Mark Lawrence

On 21/10/2013 08:43, Chris Angelico wrote:

On Mon, Oct 21, 2013 at 6:39 PM, Mark Lawrence  wrote:

On 21/10/2013 08:31, Chris Angelico wrote:


"I use Google Groups and it sucks, so I delete all the context because
then nobody can see how much it sucks at showing context."



Because it's written in (say) C++ in an object orientated style, so by
rewriting it using assembler in a procedural style it will be fixed?


Certainly not. The solution is to use FORTRAN and functional style.
That should be obvious!

ChrisA



Thank you for the correction, my mistake I'm afraid :(

--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Python was designed (was Re: Multi-threading in Python vs Java)

2013-10-21 Thread Steven D'Aprano
On Sun, 20 Oct 2013 23:44:27 -0700, Peter Cacioppi wrote:

> This is just one language feature. I could go on and on. The idea that
> the differences between these languages is just syntactic sugar and
> aesthetics is so profoundly misguided that I can only assume that this
> misconception was proposed as a bizarre form of trolling.

I don't know who you are responding to, or what they said to give you the 
impression that they believe that all differences between languages is 
*merely* syntactic sugar, but I certainly don't believe that.

In fact, given that you haven't quoted anyone, I'm tempted to call it a 
straw-man, except you don't appear to be arguing against anyone, so there 
is nobody it could be a straw-man of :-)



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


Re: Python was designed (was Re: Multi-threading in Python vs Java)

2013-10-21 Thread Metallicow
Python is the Best!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python was designed (was Re: Multi-threading in Python vs Java)

2013-10-21 Thread Peter Cacioppi
Specifically the following seems so misguided as to be deliberate trolling.

"One of the reasons multiple languages exist is because people find that 
useful programming idioms and styles are *hard to use* or "ugly" in some 
languages, so they create new languages with different syntax to make 
those useful patterns easier to use."

This is just profoundly wrong. If anything, different languages strive to 
maintain common syntax. You can see foo.bar() as legal syntax meaning 
essentially the same thing in C++, C#, Java and Python (and likely quite a few 
other languages). There is NOT a deliberate effort to create new syntax just 
for aesthetics, there is the exact opposite. There is a deliberate effort to 
maintain consistency with the syntax of pre-existing languages.

Languages sprout up for a variety of reasons. C++ has very significant 
functionality that doesn't exist in C. Java/C# can say the same thing to C++, 
and Python to all of the others. 

Please lets not pretend that it's all just ballpark equivalent facades 
plastered on top of a Turing machine. New languages pop up to automate boring 
and repetitive tasks that chew up your time in older languages. That's the 
trend - abstractions automating repetitious and error-prone tasks. 

Not "hey, this syntax isn't too my taste, I'm going to toodle it up".
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python was designed (was Re: Multi-threading in Python vs Java)

2013-10-21 Thread Metallicow
Are you suggesting Advertising is the Best language there is?
# After many years, I agree not, but what to may...
def If I do Something do, you not react():
 IsMySyntaxNotCorrect()
 CanINotCorrectMyGrammaticalMistakesAndSeekAcceptance():
 # The most arguable language is arguably the most important to discuss.
 # Everyone is of the same basic mindset here.
 # 16 years of reading everyone elses words hasn't changed my view.
 # I make it real, and sometime I don't like it either.
 # Actions speak loader than comments.
 language = python

 benefits = failures
 failures = newTerminology
 newTerminology = newIdeas
 newIdeas = benefits

 Sometimes when the whole world doesn't complain about your 
newTerminology, they are trying to say let it live, but more often they say 
"leave it alone". And Vise Versa.

 But more often they complain about the readability.
 Or the Indenation.
 Or the style of a personal poem.
 Or how the next person should learn it best.
 
I read a indented book first, then I read a un indented book. Sir.
  go figure
 nowpost()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-21 Thread Oscar Benjamin
On 21 October 2013 08:46, Steven D'Aprano  wrote:
> On Sun, 20 Oct 2013 20:35:03 -0700, Mark Janssen wrote:
>
> [Attribution to the original post has been lost]
>>> Is a jit implementation of a language (not just python) better than
>>> traditional ahead of time compilation.
>>
>> Not at all.  The value of jit compilation, I believe, is purely for the
>> dynamic functionality that it allows.  AOT compilation will never allow
>> that, but in return you get massive performance and runtime-size gains
>
> On the contrary, you have that backwards. An optimizing JIT compiler can
> often produce much more efficient, heavily optimized code than a static
> AOT compiler, and at the very least they can optimize different things
> than a static compiler can. This is why very few people think that, in
> the long run, Nuitka can be as fast as PyPy, and why PyPy's ultimate aim
> to be "faster than C" is not moonbeams:

That may be true but both the examples below are spurious at best. A
decent AOT compiler would reduce both programs to the NULL program as
noted by haypo:
http://morepypy.blogspot.co.uk/2011/02/pypy-faster-than-c-on-carefully-crafted.html?showComment=1297205903746#c2530451800553246683

> http://morepypy.blogspot.com.au/2011/02/pypy-faster-than-c-on-carefully-crafted.html
>
> http://morepypy.blogspot.com.au/2011/08/pypy-is-faster-than-c-again-string.html

I just modified the add() example so that none of the operations can
be entirely optimised away:

def main():
i = 0
a = 0.0
b = 0.0
while i < 10:
a += 1.0
b += add(a, a)
i += 1
print(b)

Similarly for the C version:

#include 

double add(double a, double b);

int main()
{
  int i = 0;
  double a = 0;
  double b = 0;
  while (i < 10) {
a += 1.0;
b += add(a, a);
i++;
  }
  printf("%f", b);
}

My timings:

$ gcc -O3 x.c y.c
$ time ./a.exe
10134218000.00
real0m5.609s
user0m0.015s
sys 0m0.000s
$ time pypy y.py
1.013e+18

real0m9.891s
user0m0.060s
sys 0m0.061s

So the pypy version takes twice as long to run this. That's impressive
but it's not "faster than C".

I also compared a script that uses intensive decimal computation run
under CPython 3.3 and PyPy 2.1 (pyver 2.7). This is essentially a
comparison between the C implementation of the decimal module and
pypy's jit'd optimisation of the pure Python module. CPython 3.3 takes
10 seconds and PyPy 2.1 takes 45 seconds. Again that's impressive (a
lot of work went into making the C implementation of the decimal
module as fast as it is) but it's not faster than C.

I don't mean to criticise PyPy. I've just tested it and I am impressed
and I think I'll definitely try and use it where possible. I do think
that some of the marketing there is misleading though.


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


Re: Python Front-end to GCC

2013-10-21 Thread Philip Herron
Hey all,

Thanks, i've been working on this basically on my own 95% of the compiler is 
all my code, in my spare time. Its been fairly scary all of this for me. I 
personally find this as a real source of interest to really demystify compilers 
and really what Jit compilation really is under the hood.

For example if your really interested to see what jit compilation really is 
(not magic) look at:
http://compilers.iecc.com/comparch/article/10-03-063

And i really believe in this project. Though i really want to say away from 
comparing my project to any others out there. As they are much more mature than 
mine.

For example its only a few commits back your successfully able to compile:

import sys

So i think its fairly unfair comparisons could get me into trouble. Whats taken 
so long is i do not reuse the python runtime like the others. Other projects do 
this to maintain computability mostly. But i wanted to test doing this entirely 
from scratch partly for my own interest and that the python runtime was 
designed for an interpreter, not compilers at least ahead of time.

Its interesting a few things come up what about:

exec and eval. I didn't really have a good answer for this at my talk at PYCon 
IE 2013 but i am going to say no. I am not going to implement these. Partly 
because eval and exec at least to me are mostly from developing interpreters as 
a debugging exercise so the test doesn't have to invoke the program properly 
and feed in strings to interpret at least thats what i have done in the past 
with an virtual machine i wrote before gccpy.

I think anything you look up on eval and exec you shouldn't use them in 
production code as it could lead to a lot of issues. I can see their use in 
quick dirty uses but i don't think they really are part of the python language 
in my opinion its just some builtin functions that you can invoke. Another 
issue i had was:

class myClass: pass

I currently don't allow this but i've re thought this and i am going to try and 
implement this properly before i had a really complicated to pass to quess the 
type of a struct but i realise currently with how things work this may not be 
the case.

As a personal comment i think this is kind of funny as why not use a dict. But 
i can see the use for it now, and i want to implement it.

What i will say is gccpy is moving along with each milestone i will achieve 
over the course of the first half of 2014 i reckon i could at least compile 
half of a decnt python test suite. Its taken me so long to get used to the GCC 
code base and how i want to implement things i've re-wrote the runtime and the 
compiler probably at least 4 times and i am going to rewrite part of the 
runtime today for the next week or so. I think tis a worth while project.

I don't think this will ever be on par with PyPy or CPython as professional as 
those projects are i really respect their work i mean i look up to them (loads) 
i am just a guy who likes compilers and it isnt my day job i don't get paid for 
this i just enjoy the challenge and i hope you understand that this is my baby 
and i am very protective of my project :).

I hope in a few months when i start compiling testsuiites i will publish 
benchmarks what i will say is it looks pretty good right now only 1 case so far 
(that i have tested) where i am not faster than CPython and its only because i 
havent been compiling the runtime library with correct CFLAGS like -O2 etc i 
wasnt passing anything another is i have tonnnes of debugging malloc all over 
the show slowing it down because i need to rewrite part of the runtime so yeah. 
I've been fighting GCC for 4 years now i am fighting my own code ;).

Final note i am not saying JIT is bad or not the way to do things i personally 
think this question isn't answered and i can see the case for it there are down 
sides that jit people wont talk about.

The complexity of maintaining a j it in project is probably the main one and 
optimisations at runtime make it even more mental as they are hard to do is an 
under statement never mind they aren't as common as you would want to believe 
outside of target specifics which gcc already knows (-mtune*). I do believe JIT 
is the way forward but i think something in languages needs to really be 
designed from that perspective and maybe even cpu's to help with some kind of 
instructions to help maintain a destination between runtime and user code or 
something (making tail call optimisations easier on dynamic languages) maybe?

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


Re: Python was designed (was Re: Multi-threading in Python vs Java)

2013-10-21 Thread rusi
On Monday, October 21, 2013 2:13:52 PM UTC+5:30, Peter Cacioppi wrote:
> Specifically the following seems so misguided as to be deliberate trolling.

The same could be said for this below… but…

> 
> "One of the reasons multiple languages exist is because people find that 
> useful programming idioms and styles are *hard to use* or "ugly" in some 
> languages, so they create new languages with different syntax to make 
> those useful patterns easier to use."
> 
> 
> This is just profoundly wrong. If anything, different languages strive to 
> maintain common syntax. You can see foo.bar() as legal syntax meaning 
> essentially the same thing in C++, C#, Java and Python (and likely quite a 
> few other languages). There is NOT a deliberate effort to create new syntax 
> just for aesthetics, there is the exact opposite. There is a deliberate 
> effort to maintain consistency with the syntax of pre-existing languages.
> 
> 
> 
> Languages sprout up for a variety of reasons. C++ has very significant 
> functionality that doesn't exist in C. Java/C# can say the same thing to C++, 
> and Python to all of the others. 
> 
> 
> Please lets not pretend that it's all just ballpark equivalent facades 
> plastered on top of a Turing machine. New languages pop up to automate boring 
> and repetitive tasks that chew up your time in older languages. That's the
> trend - abstractions automating repetitious and error-prone tasks. 
> 
> 
> 
> Not "hey, this syntax isn't too my taste, I'm going to toodle it up".


… but I am not going to do so.
Instead I reiterate:

The whole point of studying programming language semantics is just so that we 
can distinguish between the 'just toodle it up' differences and the bigger ones.
And so projects that take the Alice' Humpty Dumpty attitude:

"When I use a word," Humpty Dumpty said in rather a scornful tone, "it means 
just what I choose it to mean -- neither more nor less." 

should be treated with suspicion in correspondence with the scorn.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python was designed (was Re: Multi-threading in Python vs Java)

2013-10-21 Thread Roy Smith
On Mon, Oct 21, 2013 at 1:07 PM, Steven D'Aprano 
 wrote:
> One of the reasons multiple languages exist is because people find that
> useful programming idioms and styles are *hard to use* or "ugly" in some
> languages, so they create new languages with different syntax to make
> those useful patterns easier to use. But syntax is not everything.
> Whether you write:
>
> object.method(arg)// Python, VB, Ruby, Java
> object#method arg // OCaml
> object:method arg // Lua
> method object arg // Haskell, Mercury
> object method arg // Io
> object->method(arg)   // C++, PHP
> method(object, arg)   // Ada, Dylan
> send method(arg) to object  // XTalk family of languages

You missed the ever-so-special Objective C syntax:

[object method arg1 withSomething arg2 withSomethingElse arg3]

I'm sure I got that slightly wrong.  I don't do Objective C, and my eyes 
glaze over every time I have to read it.

And, of course, there's Postscript (stolen from Forth) stack syntax:

arg3
arg2
arg1
function

although it's more than just syntax; it's a totally different program 
architecture.  A lot of people don't realize that PostScript is not just 
a printer file format, it's a real language with functions, variables, 
loops, and all that good stuff.
-- 
https://mail.python.org/mailman/listinfo/python-list


IDLE being too clever checking nonlocal declarations?

2013-10-21 Thread Chris Angelico
Try typing this into IDLE:

>>> def a():
def b():
nonlocal q
SyntaxError: no binding for nonlocal 'q' found


In interactive command-line Python, this doesn't throw an error, and
it works fine if the name is used later:

>>> def a():
def b():
nonlocal q
q+=1
q=1
b()
return q

>>> a()
2

But typing this into IDLE interactive mode requires some fiddling
around with the editor. Is it trying to be too clever? Am I doing
something that makes no sense?

Tested with 3.3.0 on Windows XP.

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


Class construction

2013-10-21 Thread Demian Brecht
Hi all,

I'm trying to wrap my head around how classes are constructed at the
interpreter level (as a side effect of digging into metaclasses) and
I'm hoping to have my investigation either validated or ridiculed ;)

The pipeline that I've figured through some gdb debugging (starting at
type_call):

+ type_call
  + is there a metaclass for this object?
+ return metaclass->tp_new
  + roughly 350 LOC constructing the type
  + is object is not a subclass of type?
 + return object
   + call obj->tp_init

Does that sound correct? My C/gdb skills are horribly rusty at this
point so expert insight would help :)

Thanks,

-- 

Demian Brecht
http://demianbrecht.github.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Printing a drop down menu for a specific field.

2013-10-21 Thread Joel Goldstick
On Mon, Oct 21, 2013 at 3:31 AM, Mark Lawrence  wrote:
>
> On 21/10/2013 07:07, Νίκος Αλεξόπουλος wrote:
>>
>>
>> Any help would be appreciated.
>
>
> It is considered polite to wait for at least 24 hours before pinging. If 
> waiting for this time isn't an option then paying for support is.
>
> --
> Python is the second best programming language in the world.
> But the best has yet to be invented.  Christian Tismer
>
> Mark Lawrence
>
> --
> https://mail.python.org/mailman/listinfo/python-list


There is nothing about this question that relates to python.

1. You are asking in a very ill defined way how to collect all of the
times your visitors visited.  That's really a sql issue.
2. Your present html is written in a style that was considered ok in
1998.  CSS has replaced most of the stuff in your html.  This
highlights your lack of diligence to learn proper techniques in any
area -- not just python, or http, but now html.

My suggestion is that you should write the html by hand, and see if it
does what you want it to do.  Once you figure that out, go back to
your code and see if you can write python code that will mimic what
you wrote by hand.

You have been told in previous discussions, that writing html code in
your python code that performs back end logic is a TERRIBLE idea as it
leads to a mess in the code that is difficult to change even in minor
ways, and difficult to debug.  You have proven this to be true with
your long miandering debug pleas that you bring here.

best wishes Iron head


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


Re: IDLE being too clever checking nonlocal declarations?

2013-10-21 Thread Peter Otten
Chris Angelico wrote:

> Try typing this into IDLE:
> 
 def a():
> def b():
> nonlocal q
> SyntaxError: no binding for nonlocal 'q' found
> 
> 
> In interactive command-line Python, this doesn't throw an error, and
> it works fine if the name is used later:
> 
 def a():
> def b():
> nonlocal q
> q+=1
> q=1
> b()
> return q
> 
 a()
> 2
> 
> But typing this into IDLE interactive mode requires some fiddling
> around with the editor. Is it trying to be too clever? Am I doing
> something that makes no sense?

Yes, but you should still file a bug report ;)
 
> Tested with 3.3.0 on Windows XP.

Confirmed on Linux for 3.2.2, 3.3.0, and an outdated built of 3.4. It looks 
like all versions of Python 3 are affected.

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


Re: IDLE being too clever checking nonlocal declarations?

2013-10-21 Thread Chris Angelico
On Tue, Oct 22, 2013 at 3:09 AM, Peter Otten <__pete...@web.de> wrote:
> Chris Angelico wrote:
>> But typing this into IDLE interactive mode requires some fiddling
>> around with the editor. Is it trying to be too clever? Am I doing
>> something that makes no sense?
>
> Yes, but you should still file a bug report ;)

Heh. I like doing things that make no sense, sometimes :)

>> Tested with 3.3.0 on Windows XP.
>
> Confirmed on Linux for 3.2.2, 3.3.0, and an outdated built of 3.4. It looks
> like all versions of Python 3 are affected.

Thanks for the confirmation. http://bugs.python.org/issue19335 created.

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


Re: skipping __init__ and using exploiting a class member instead

2013-10-21 Thread Neil Cerutti
On 2013-10-20, Ben Finney  wrote:
> Roy Smith  writes:
>
>> Scott Meyers is an incredibly smart C++ wizard.  His books are amazing.  
>> The fact that it takes somebody that smart, and books that amazing, to 
>> teach you how not to shoot yourself in the foot with a C++ compiler says 
>> a lot about the language.
>
> +1 QotW

The existence of the STL shows a counterpoint to the complexity.
There are rewards for the complexity, in other words. Some of the
recipes in Meyers' books are amazing: The combination of class
templates, the envelope pattern, and template specialization, for
example; you get a generic interface with a decoupled
implementation which can be optimized for specific types at need.

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


Re: IDLE being too clever checking nonlocal declarations?

2013-10-21 Thread Terry Reedy

On 10/21/2013 11:06 AM, Chris Angelico wrote:

Try typing this into IDLE:


def a():

 def b():
 nonlocal q
SyntaxError: no binding for nonlocal 'q' found


If you submit those three lines to Python from the command line, that is 
what you see.



In interactive command-line Python, this doesn't throw an error,
it works fine if the name is used later:


def a():

 def b():
 nonlocal q
 q+=1


I verified that interactive Python also syntax checks each line as 
entered, even for compound statements. Details should be left to the 
tracker issue you raised.


--
Terry Jan Reedy

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


Re: What's wrong with Windows Command Prompt (was Re: Error Testing)

2013-10-21 Thread David Robinow
On Sat, Oct 19, 2013 at 4:35 PM, Terry Reedy  wrote:
> On 10/19/2013 2:31 PM, Tim Chase wrote:
>>
>> On 2013-10-19 14:08, David Robinow wrote:
>>>
>>> On Sat, Oct 19, 2013 at 9:01 AM, Chris Angelico wrote:

 You can try all these out in the interactive interpreter (you
 probably have IDLE installed, which on Windows is rather nicer to
 work with than the default interactive mode).
>>>
>>>
>>>   IDLE is cross-platform.  Could you explain why you say "on
>>> Windows"?
>> ...
>  [Description of idle  vs. Command Prompt]
 Not quite what I was trying to ask.
I'm well aware that Idle has features that the Python interpreter on
Windows doesn't.
Idle also has features that the unix variants doesn't.
I don't use my Ubuntu much so I'm somewhat ignorant, but I wasn't
aware that the interactive interpreter on Linux had features that the
Windows version didn't. I'm curious what those features might be.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-21 Thread Mark Janssen
On Mon, Oct 21, 2013 at 12:46 AM, Steven D'Aprano  wrote:
> On Sun, 20 Oct 2013 20:35:03 -0700, Mark Janssen wrote:
>
> [Attribution to the original post has been lost]
>>> Is a jit implementation of a language (not just python) better than
>>> traditional ahead of time compilation.
>>
>> Not at all.  The value of jit compilation, I believe, is purely for the
>> dynamic functionality that it allows.  AOT compilation will never allow
>> that, but in return you get massive performance and runtime-size gains
>
> On the contrary, you have that backwards. An optimizing JIT compiler can
> often produce much more efficient, heavily optimized code than a static
> AOT compiler,

This is horseshit.

> and at the very least they can optimize different things
> than a static compiler can.

Okay sure.  But now you've watered down your claim that's it's not
saying much of anything.

> This is why very few people think that, in
> the long run, Nuitka can be as fast as PyPy, and why PyPy's ultimate aim
> to be "faster than C" is not moonbeams:

It is moonbeams, but that's a good thing.  I think you don't
understand how computers work, Steven.
In any event, PyPy is a great project for those who want experiment
with compiler and language design.

> JIT compilation is really about optimization,

No.

> which is why languages like
> Java and .NET which could easily be compiled to machine code at compile
> time generally use an intermediate bytecode and a JIT compiler instead.
> They're not doing it for dynamism since they aren't dynamic languages.
> It's a way of generating more aggressive (i.e. better but harder)
> optimizations based on information only available at runtime.

This must is true, but not for reasons you understand.

-- 
MarkJ
Tacoma, Washington
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-21 Thread Mark Janssen
On Mon, Oct 21, 2013 at 4:08 AM, Philip Herron
 wrote:
> Thanks, i've been working on this basically on my own 95% of the compiler is 
> all my code, in my spare time. Its been fairly scary all of this for me. I 
> personally find this as a real source of interest to really demystify 
> compilers and really what Jit compilation really is under the hood.

So I'm curious, not having looked at your code, are you just
translating python code into C code to make your front-end to gcc?
Like converting "[1,2,3]" into a C linked-list data structure and
making 1 an int (or BigNum?)?

-- 
MarkJ
Tacoma, Washington
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's wrong with Windows Command Prompt (was Re: Error Testing)

2013-10-21 Thread Tim Chase
On 2013-10-21 15:55, David Robinow wrote:
> I wasn't aware that the interactive interpreter on Linux had
> features that the Windows version didn't. I'm curious what those
> features might be.

It's mostly the benefits that come from being built with the readline
library, meaning you get

- command history (Win32 offers this, the rest not AFAIK)

- command-history searchability (control+R)

- the ability to pull down things from previous lines (alt+period in
  particular)

- the ability to comment out the currently typed command without
  executing it (alt+octothorpe)

- the ability to prefix text/commands with a count
  (alt+number_of_times followed by the character/command)

- the ability to insert matching filenames (alt+asterisk after typing
  path relative to the $CWD)

- clearing to the start/end of line (control+U/control+K)

- the ability to paste content (control+Y) previously-cut by ^U/^K

- the ability to transpose adjacent words (alt+T)

- the ability to jump forward/backward to a specified character
  (control+] and control+alt+] followed by the target char) like f/F
  in vi/vim

Those are just a subset of the power offered by readline when built
into Python's interpreter, none of which work (other than that first
one) on Win32's cmd.exe (or, I suppose command.com).

-tkc




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


Re: Python Front-end to GCC

2013-10-21 Thread Ned Batchelder

On 10/21/13 4:14 PM, Mark Janssen wrote:

On Mon, Oct 21, 2013 at 12:46 AM, Steven D'Aprano  wrote:

On Sun, 20 Oct 2013 20:35:03 -0700, Mark Janssen wrote:

[Attribution to the original post has been lost]

Is a jit implementation of a language (not just python) better than
traditional ahead of time compilation.

Not at all.  The value of jit compilation, I believe, is purely for the
dynamic functionality that it allows.  AOT compilation will never allow
that, but in return you get massive performance and runtime-size gains

On the contrary, you have that backwards. An optimizing JIT compiler can
often produce much more efficient, heavily optimized code than a static
AOT compiler,

This is horseshit.


Surely we can discuss this without resorting to swearing.

and at the very least they can optimize different things
than a static compiler can.

Okay sure.  But now you've watered down your claim that's it's not
saying much of anything.


This is why very few people think that, in
the long run, Nuitka can be as fast as PyPy, and why PyPy's ultimate aim
to be "faster than C" is not moonbeams:

It is moonbeams, but that's a good thing.  I think you don't
understand how computers work, Steven.
I think Steven has earned the benefit of the doubt when it comes to 
understanding computer.  Did you read the links he provided? Do you 
believe that author also doesn't understand how computers work?


Mark, disagreement doesn't have to lead to ad-hominem attacks.  If you 
think Steven is wrong about what JIT compilers can do, please explain.  
Simply calling his statements horseshit and saying he doesn't understand 
computers is not a rebuttal.



In any event, PyPy is a great project for those who want experiment
with compiler and language design.


JIT compilation is really about optimization,

No.


Please tell us what JIT compilation is about.



which is why languages like
Java and .NET which could easily be compiled to machine code at compile
time generally use an intermediate bytecode and a JIT compiler instead.
They're not doing it for dynamism since they aren't dynamic languages.
It's a way of generating more aggressive (i.e. better but harder)
optimizations based on information only available at runtime.

This must is true, but not for reasons you understand.


Again, a statement with no supporting information.

*sigh*

If someone says something that seems wrong to you, there are a number of 
possibilities: 1) you are wrong, 2) they are wrong, or 3) you haven't 
understood each other yet.  Please have the humility to at least 
consider option 3 first.


--Ned.

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


python -c commands on windows.

2013-10-21 Thread Terry Reedy

Manual says "-c 
Execute the Python code in command. command can be one or more 
statements separated by newlines, with significant leading whitespace as 
in normal module code."


In Windows Command Prompt I get:
C:\Programs\Python33>python -c "a=1\nprint(a)"
  File "", line 1
a=1\nprint(a)
^
SyntaxError: unexpected character after line continuation character
(Same if I remove quotes.)

How do I get this to work?

--
Terry Jan Reedy

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


Re: Python Front-end to GCC

2013-10-21 Thread Philip Herron
On Monday, 21 October 2013 21:26:06 UTC+1, zipher  wrote:
> On Mon, Oct 21, 2013 at 4:08 AM, Philip Herron
> 
>  wrote:
> 
> > Thanks, i've been working on this basically on my own 95% of the compiler 
> > is all my code, in my spare time. Its been fairly scary all of this for me. 
> > I personally find this as a real source of interest to really demystify 
> > compilers and really what Jit compilation really is under the hood.
> 
> 
> 
> So I'm curious, not having looked at your code, are you just
> 
> translating python code into C code to make your front-end to gcc?
> 
> Like converting "[1,2,3]" into a C linked-list data structure and
> 
> making 1 an int (or BigNum?)?
> 
> 
> 
> -- 
> 
> MarkJ
> 
> Tacoma, Washington

No its not like those 'compilers' i dont really agree with a compiler 
generating C/C++ and saying its producing native code. I dont really believe 
its truely within the statement. Compilers that do that tend to put in alot of 
type saftey code and debugging internals at a high level to get things working 
in other projects i am not saying python compilers here i havent analysed 
enough to say this.

What i mean as a front-end is jut like GCC G++ gccgo gfortran it all works the 
same each of these are front-ends you can pass all those mental gcc options 
like -O3 -mtune -fblabla. it is implemented as part of gcc and you can 
'bootstrap python'. You can -fdump-tree-all etc.

What i can say is jit compilation is really mistified' in a big way when it 
comes to projects like pypy when its implemented in python how can it call mmap 
to make an executable memory block etc. When it comes to compilation i think it 
gets fairly mistified in the python compiler community even more.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python -c commands on windows.

2013-10-21 Thread random832
On Mon, Oct 21, 2013, at 16:47, Terry Reedy wrote:
> Manual says "-c 
>  Execute the Python code in command. command can be one or more 
> statements separated by newlines, with significant leading whitespace as 
> in normal module code."
> 
> In Windows Command Prompt I get:
> C:\Programs\Python33>python -c "a=1\nprint(a)"
>File "", line 1
>  a=1\nprint(a)
>  ^
> SyntaxError: unexpected character after line continuation character
> (Same if I remove quotes.)
> 
> How do I get this to work?

Well, ignoring the "why would you want to" factor... this actually _is_
possible.

C:\>python -c a=1^
More?
More? print(a)
1

You can put quotes around any part of the command you need spaces in,
but you _cannot_ have the ^ in quotes. So, with quotes, it would be as
follows:

C:\>python -c "a='1 2'"^
More?
More? print(a)
1 2

This is a very obscure feature of the command processor, and I don't
know if it works inside a batch file.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea.

2013-10-21 Thread Peter Cacioppi
Just because the CPython implementation does something doesn't mean that thing 
is something other than risky/tricky/to-be-avoided-if-possible. Python (and 
it's implementations) exist so that ordinary people can avoid doing risky stuff.

I'm not critiquing the CPython implementation here, I'm pointing out that some 
languages are just better than others for most projects. Working in a higher 
level where gotos aren't needed is the right call most of the time. 

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


Re: python -c commands on windows.

2013-10-21 Thread Chris Angelico
On Tue, Oct 22, 2013 at 8:14 AM,   wrote:
> C:\>python -c a=1^
> More?
> More? print(a)
> 1

Note that you have to hit enter *twice* for this to work. (I'm not
sure why; the caret is supposed to escape the newline, but that
doesn't explain this. For all I know, it could be an ascended bug[1].)
Also, if you want to indent a subsequent line, you'll (obviously) have
to quote it (at least, if you use spaces; I don't know of a way to
insert a tab character), so this gets ugly REAL fast for conditionals:

C:\Python33>python -c "if True:"^
More?
More? " print(1)"^
More?
More? else":"^
More?
More? " print(2)"
1

Makes bash look pretty awesome!

ChrisA

[1] http://tvtropes.org/pmwiki/pmwiki.php/Main/AscendedGlitch
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea.

2013-10-21 Thread Mark Lawrence

On 17/10/2013 00:36, Skybuck Flying wrote:


Unfortunately python does not have labels and goto statements as far as
I know



http://entrian.com/goto/

--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: python -c commands on windows.

2013-10-21 Thread Ned Batchelder

On 10/21/13 4:47 PM, Terry Reedy wrote:

Manual says "-c 
Execute the Python code in command. command can be one or more 
statements separated by newlines, with significant leading whitespace 
as in normal module code."


In Windows Command Prompt I get:
C:\Programs\Python33>python -c "a=1\nprint(a)"
  File "", line 1
a=1\nprint(a)
^
SyntaxError: unexpected character after line continuation character
(Same if I remove quotes.)

How do I get this to work?

You could use semicolons:  python -c "a = 1; print(a)"   If your code is 
too long for that, it sounds horrible to put it in the command line...


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


Re: python -c commands on windows.

2013-10-21 Thread Terry Reedy

On 10/21/2013 5:14 PM, random...@fastmail.us wrote:

On Mon, Oct 21, 2013, at 16:47, Terry Reedy wrote:

Manual says "-c 
  Execute the Python code in command. command can be one or more
statements separated by newlines, with significant leading whitespace as
in normal module code."

In Windows Command Prompt I get:
C:\Programs\Python33>python -c "a=1\nprint(a)"
File "", line 1
  a=1\nprint(a)
  ^
SyntaxError: unexpected character after line continuation character
(Same if I remove quotes.)

How do I get this to work?


Well, ignoring the "why would you want to" factor...


Because it is claimed to be possible ;-)

That particular example could be written in one line with ';'. But it is 
a minimal example that either shows the problem or obviously works. (IE, 
what we recommend people post ;-). I initially tried to test a version 
of Chris Angelico's code from another thread without writing it to a file:


def a():
  def b():
nonlocal c

I also wanted to know if 'newline' in the doc meant a literal newline 
(it appears so, but it seemed impossible on Windows) rather than '\n' 
and if the problem was peculiar to Windows. And I need to know that to 
run "python -c ... " in a subproccess from Python.




this actually _is_ possible.


Even on Windows .. I presume this is easier on *nix.


C:\>python -c a=1^
More?
More? print(a)
1

You can put quotes around any part of the command you need spaces in,
but you _cannot_ have the ^ in quotes. So, with quotes, it would be as
follows:

C:\>python -c "a='1 2'"^
More?
More? print(a)
1 2


Spaces would be typical for a compound statememt header line. For a 
third line, the second should have ^ added.



This is a very obscure feature of the command processor,


Really obscure ;-)

> and I don't know if it works inside a batch file.

It does:
---tem.bat
python -c "def f(a):"^

"  print(a+1)"^

f(2)
---Command Prompt
C:\Programs\Python33>\Users\Terry\Documents\tem

C:\Programs\Python33>python -c "def f(a):"
"  print(a+1)"
f(2)
3
---
3 lines echoed (they could have been suppressed) plus output.

--
Terry Jan Reedy

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


Re: Class construction

2013-10-21 Thread Marcin Szamotulski
You can inspect the process in this way:

>>> c = 'class A: pass'
>>> code = compile(c, '', 'exec')
>>> from dis import dis
>>> dis(code)
1   0 LOAD_BUILD_CLASS 
1 LOAD_CONST   0 (", line 1>) 
4 LOAD_CONST   1 ('A') 
7 MAKE_FUNCTION0 
   10 LOAD_CONST   1 ('A') 
   13 CALL_FUNCTION2 (2 positional, 0 keyword pair) 
   16 STORE_NAME   0 (A) 
   19 LOAD_CONST   2 (None) 
   22 RETURN_VALUE

(this is in Python3.3, in Python2.7 the result will be different)

Now you can check ceval.c (PyEval_EvalFrameEx function) what are the
above opcode's doing.  For example LOAD_BUILD_CLASS pushes the buildin
function builtins.__build_class__ to the stack and then CALL_FUNCTION
calls it.  the c implementation of __build_class__ is in
Python/bltinmodule.c (builtin___build_class__).  Indeed this function
will call the metaclass->tb_new `method` (but before it will also call
the __prepare__ method on metaclass to get the namespace).  The first
argument on builtin__build_class__ is a function object which correspond
to the class body, and it is evaluated in the class namespace.

So the process (with some simplifications) goes like this:

1. get metaclass: meta
2. call meta.__prepare__ to get namespace (class __dict__)
3. evaluate the class body in the namespace
4. call meta with arguemnts: name, bases, namespace
(when you instantiate any class in Python, metaclass is just
a class, first its __new__ method is called, and then its __init__) 

All this is in builtin__build_class__.

I hope it helps,
Regards,
Marcin

On 08:08 Mon 21 Oct , Demian Brecht wrote:
> Hi all,
> 
> I'm trying to wrap my head around how classes are constructed at the
> interpreter level (as a side effect of digging into metaclasses) and
> I'm hoping to have my investigation either validated or ridiculed ;)
> 
> The pipeline that I've figured through some gdb debugging (starting at
> type_call):
> 
> + type_call
>   + is there a metaclass for this object?
> + return metaclass->tp_new
>   + roughly 350 LOC constructing the type
>   + is object is not a subclass of type?
>  + return object
>+ call obj->tp_init
> 
> Does that sound correct? My C/gdb skills are horribly rusty at this
> point so expert insight would help :)
> 
> Thanks,
> 
> -- 
> 
> Demian Brecht
> http://demianbrecht.github.com
> -- 
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-21 Thread Mark Janssen
> No its not like those 'compilers' i dont really agree with a compiler 
> generating C/C++ and saying its producing native code. I dont really believe 
> its truely within the statement. Compilers that do that tend to put in alot 
> of type saftey code and debugging internals at a high level to get things 
> working in other projects i am not saying python compilers here i havent 
> analysed enough to say this.

Hmm, well what I'd personally find interesting from a computer science
point of view is a app that will take a language specification in BNF
(complete with keywords and all) and output C code which is then
compiled to an executable as normal.  This is how a front-end should
be designed.  A middle-layer for translating common language elements
like lists, sets, etc, could make it easy.

-- 
MarkJ
Tacoma, Washington
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to get current max_heap_size value of minimark in pypy 2.x

2013-10-21 Thread Steven D'Aprano
Hi Ricky,

On Sun, 20 Oct 2013 19:53:18 -0700, roadhome wrote:

> I read some articles about setting PYPY_GC_MAX environment variable. But
> I can't find how to get current max_heap_size value of minimark.

Unfortunately it seems that not a lot of people here have enough 
experience with PyPy to answer your question. Perhaps you should ask on a 
specialist PyPy mailing list? Perhaps try here?

http://mail.python.org/mailman/listinfo/pypy-dev

If you do get an answer elsewhere, please consider writing back here with 
that answer so as to help anyone else in the future.

Good luck,


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


Re: Python Front-end to GCC

2013-10-21 Thread Steven D'Aprano
On Mon, 21 Oct 2013 10:55:10 +0100, Oscar Benjamin wrote:

> On 21 October 2013 08:46, Steven D'Aprano  wrote:

>> On the contrary, you have that backwards. An optimizing JIT compiler
>> can often produce much more efficient, heavily optimized code than a
>> static AOT compiler, and at the very least they can optimize different
>> things than a static compiler can. This is why very few people think
>> that, in the long run, Nuitka can be as fast as PyPy, and why PyPy's
>> ultimate aim to be "faster than C" is not moonbeams:
> 
> That may be true but both the examples below are spurious at best. A
> decent AOT compiler would reduce both programs to the NULL program as
> noted by haypo:
> http://morepypy.blogspot.co.uk/2011/02/pypy-faster-than-c-on-carefully-
crafted.html?showComment=1297205903746#c2530451800553246683

Are you suggesting that gcc is not a decent compiler? If "optimize away 
to the null program" is such an obvious thing to do, why doesn't the most 
popular C compiler in the [FOSS] world do it?


[...]
> So the pypy version takes twice as long to run this. That's impressive
> but it's not "faster than C".

Nobody is saying that PyPy is *generally* capable of making any arbitrary 
piece of code run as fast as hand-written C code. You'll notice that the 
PyPy posts are described as *carefully crafted* examples.

I believe that, realistically, PyPy has potential to bring Python into 
Java and .Net territories, namely to run typical benchmarks within an 
order of magnitude of C speeds on the same benchmarks. C is a very hard 
target to beat, because vanilla C code does *so little* compared to other 
languages: no garbage collection, no runtime dynamism, very little 
polymorphism. So benchmarking simple algorithms plays to C's strengths, 
while ignoring C's weaknesses.



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


Re: IDLE being too clever checking nonlocal declarations?

2013-10-21 Thread Steven D'Aprano
On Mon, 21 Oct 2013 15:51:56 -0400, Terry Reedy wrote:

> On 10/21/2013 11:06 AM, Chris Angelico wrote:
>> Try typing this into IDLE:
>>
> def a():
>>  def b():
>>  nonlocal q
>> SyntaxError: no binding for nonlocal 'q' found
> 
> If you submit those three lines to Python from the command line, that is
> what you see.

Arguably, that's also too strict, but these *four* lines work fine 
interactively:

py> def a():
... def b():
... nonlocal q
... q = 1
...


and also from the command line:


[steve@ando ~]$ python3.3 -c "def a():
> def b():
> nonlocal q
> q = 1
> "


so it should also work in IDLE.




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


Using "with" context handler, and catching specific exception?

2013-10-21 Thread Victor Hooi
Hi,

I suspect I'm holding 

How should I use the "with" context handler as well as handling specific 
exceptions?

For example, for a file:

with open('somefile.log', 'wb') as f:
f.write("hello there")

How could I specifically catch IOError in the above, and handle that? Should I 
wrap the whole thing in a try-except block?

(For example, if I wanted to try a different location, or if I wanted to print 
a specific error message to the logfile).

try:
with open('somefile.log', 'wb' as f:
f.write("hello there")
except IOError as e:
logger.error("Uhoh, the file wasn't there").

Cheers,
Victor
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using "with" context handler, and catching specific exception?

2013-10-21 Thread MRAB

On 22/10/2013 02:43, Victor Hooi wrote:

Hi,

I suspect I'm holding

How should I use the "with" context handler as well as handling specific 
exceptions?

For example, for a file:

 with open('somefile.log', 'wb') as f:
 f.write("hello there")

How could I specifically catch IOError in the above, and handle that? Should I 
wrap the whole thing in a try-except block?


Yes, it's as simple as that.


(For example, if I wanted to try a different location, or if I wanted to print 
a specific error message to the logfile).

 try:
 with open('somefile.log', 'wb' as f:
 f.write("hello there")
 except IOError as e:
 logger.error("Uhoh, the file wasn't there").



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


Re: Python was designed (was Re: Multi-threading in Python vs Java)

2013-10-21 Thread Steven D'Aprano
On Mon, 21 Oct 2013 01:43:52 -0700, Peter Cacioppi wrote:

> Specifically the following seems so misguided as to be deliberate
> trolling.
> 
> "One of the reasons multiple languages exist is because people find that
> useful programming idioms and styles are *hard to use* or "ugly" in some
> languages, so they create new languages with different syntax to make
> those useful patterns easier to use."

As the author of that quote -- and I wonder why you're dropping 
attributions -- I can assure you I am not trolling.

Why do you think that my comment is misguided? If you don't believe that 
people write new languages because they are dissatisfied with the 
existing ones, why do you think they write new languages?

I think that my comment should be uncontroversial. At least some 
languages were invented because the author was dissatisfied with some 
existing language and wanted a "better" language. Bjarne Stroustrup wrote 
C++ to be a better C supporting data abstraction, OOP and generic 
programming, which were too hard to do right in C.

http://www.stroustrup.com/bs_faq.html

Niklaus Wirth wrote Pascal because he wanted a *simpler* language than 
Algol -- he famously walked out of one of the Algol design conferences 
because he disagreed with the direction they were taking -- and then he 
followed Pascal with Modula 2 and Oberon to be "better" Pascals, e.g. 
adding support for parallisation, which was hard to do in Pascal.

Bertrand Meyer invented Eiffel because he liked the style of Ada and the 
OOP of Stimula, and wanted to make Design By Contract easier to use.



> This is just profoundly wrong. If anything, different languages strive
> to maintain common syntax.

With respect, I think that demonstrates a lack of experience with 
programming languages. What "common syntax" do you perceive between 
languages such as these?

- Hypertalk
- Forth
- Pascal
- Lisp
- Haskell
- bash
- Inform 7
- Prolog

All of these are real languages; none of them are joke languages. If you 
aren't at least aware of their existence, and the general "feel" of their 
syntax, then you aren't qualified to comment on programming language 
syntax. The world is much bigger than just the C family of languages.

Of course, languages tend to resemble the languages that most influenced 
them, and there are distinct "family resemblances", e.g. XTalk languages, 
Algol-based languages, etc. Some pairs of languages are closer than 
others, e.g. both Hypertalk and Haskell would accept "x + 1" as a valid 
expression to evaluate one more than x, whereas in Forth it means 
something completely different.


> You can see foo.bar() as legal syntax meaning
> essentially the same thing in C++, C#, Java and Python (and likely quite
> a few other languages). There is NOT a deliberate effort to create new
> syntax just for aesthetics, there is the exact opposite. There is a
> deliberate effort to maintain consistency with the syntax of
> pre-existing languages.

Perhaps you ought to re-read my earlier comment. I did not say that 
people "create new syntax just for aesthetics". I said that one reason 
for making a new language (there may be more than one!) is if a useful 
idiom or design pattern is *hard to use* in a language. Parallel 
processing is hard in Pascal, so Wirth created Oberon; OOP is hard in C, 
so Stroustrup created C++.

Often languages aren't just "another language, plus foo" for some foo. 
Java isn't just C-with-garbage-collection-and-objects, but James Gosling 
invented Java because he wasn't happy with the level of support for 
garbage collection and OOP in existing languages. They're not just gluing 
"one more feature" on top of an existing language. Here is Rob Pike's 
explanation for why Go was invented:

http://commandcenter.blogspot.com.au/2012/06/less-is-exponentially-
more.html

Short version: they wanted a language where concurrency was easy, and 
were dissatisfied with C and C++. Pike tried to do concurrency in C++ and 
failed:

[quote]
I actually tried and failed to find a way to bring the ideas 
to C++. It was too difficult to couple the concurrent operations 
with C++'s control structures, and in turn that made it too hard
to see the real advantages. Plus C++ just made it all seem too
cumbersome, although I admit I was never truly facile in the
language. So I abandoned the idea.


Actually, depending on how you define aesthetics, that is *exactly* why 
people define new syntax. You can write loops with GOTO:

10 do this
20 do that
30 if condition GOTO 10

but it's "ugly", by which I mean it is hard to use, error prone, and not 
easily maintained. And so modern languages eschew GOTO for while loops. 
Likewise if you have while, you don't strictly need for loops as well:

i = start
while i < end:
process(i)
i += step

nevertheless compared to a for-loop, such a construct is "ugly" (harder 
to use, more error prone, less easily maintained, harder to read, harder 
to analyse), and so moder

Re: Using "with" context handler, and catching specific exception?

2013-10-21 Thread Steven D'Aprano
On Mon, 21 Oct 2013 18:43:39 -0700, Victor Hooi wrote:

> try:
> with open('somefile.log', 'wb' as f:
> f.write("hello there")
> except IOError as e:
> logger.error("Uhoh, the file wasn't there").

I hope that this isn't what you are actually doing. IOError is not just 
for "File Not Found".


py> open("/home")
Traceback (most recent call last):
  File "", line 1, in 
IOError: [Errno 21] Is a directory: '/home'

py> open("/root/foo")
Traceback (most recent call last):
  File "", line 1, in 
IOError: [Errno 13] Permission denied: '/root/foo'


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


Re: Python was designed (was Re: Multi-threading in Python vs Java)

2013-10-21 Thread Peter Cacioppi
"but it's "ugly", by which I mean it is hard to use, error prone, and not
easily maintained."

OK, I see the problem. What you call "ugly" is really just objectively bad.

Ugliness and beauty are subjective qualities that can't really be debated on a 
deep level. Like I mentioned in other post, I find the lazy-evaluation idiom 
that avoids __init__ initialization of the stored value to be pretty, so I code 
it that way (in C#, in Java, in Python, even though the syntax is slightly 
different in each one).

But I wouldn't say that using the __init__ (or the constructor) to initialize 
the lazy variable is "hard to use, error prone, not easily maintained". I would 
say it's ugly (or less pretty), and that it does seem to have some minor 
functional drawbacks. But I wouldn't make a big deal out of it if a colleague 
wanted to code it that way. 

Looking at Fortran, C, C++, C#, Java and Python (the languages I have done 
large bodies of work in, and, not coincidentally, some of the most popular 
languages ever, since I like to get paid and that requires going with the flow 
a little) it's easy to see that a lot of cosmetic things are maintained (i.e. 
foo.bar(), k += 1, etc) but some important, conceptual things are improved in 
profound ways. So a colleague that was advocating coding a project in C when 
Python would work ... yeah, that's a deal breaker, we're going to lock horns 
over that. 

I wasn't going to ramble on like this but I think you, Stephen, were the one 
encouraging me to step into the flames.



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


Re: Using "with" context handler, and catching specific exception?

2013-10-21 Thread Ben Finney
Victor Hooi  writes:

> try:
> with open('somefile.log', 'wb' as f:
> f.write("hello there")
> except IOError as e:
> logger.error("Uhoh, the file wasn't there").

IOError, as Steven D'Aprano points out, is not equivalent to “file not
found”. Also, you're not doing anything with the exception object, so
there's no point binding it to the name ‘e’.

What you want is the specific FileNotFoundError:

try:
with open('somefile.log', 'wb' as f:
f.write("hello there")
except FileNotFoundError:
logger.error("Uhoh, the file wasn't there").

See http://docs.python.org/3/library/exceptions.html#FileNotFoundError>.

-- 
 \“Choose mnemonic identifiers. If you can't remember what |
  `\mnemonic means, you've got a problem.” —Larry Wall |
_o__)  |
Ben Finney

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


Re: Python was designed (was Re: Multi-threading in Python vs Java)

2013-10-21 Thread rusi
On Tuesday, October 22, 2013 8:25:58 AM UTC+5:30, Peter Cacioppi wrote:

Guess-who said:

> "but it's "ugly", by which I mean it is hard to use, error prone, and not
> easily maintained."
> 
> OK, I see the problem. What you call "ugly" is really just objectively bad.

You continue to not attribute quotes.

What user agent/group are you using?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: IDLE being too clever checking nonlocal declarations?

2013-10-21 Thread Terry Reedy

On 10/21/2013 7:52 PM, Steven D'Aprano wrote:

On Mon, 21 Oct 2013 15:51:56 -0400, Terry Reedy wrote:


On 10/21/2013 11:06 AM, Chris Angelico wrote:

Try typing this into IDLE:


def a():

  def b():
  nonlocal q
SyntaxError: no binding for nonlocal 'q' found


If you submit those three lines to Python from the command line, that is
what you see.


Arguably, that's also too strict,


As I quoted from the doc, it is an error for a program to contain a 
nonlocal with no referent. The reason is one only needs nonlocal to bind 
and unlike with 'global newname', it would be undefined where to do the 
binding.


def a():
  def b():
def c():
  nonlocal q; q = 1

Where does q go? Replace nonlocal with global and there is no issue.

> but these *four* lines work fine interactively:


py> def a():
... def b():
... nonlocal q
... q = 1


Chris had something like this.


and also from the command line:


[steve@ando ~]$ python3.3 -c "def a():

 def b():
 nonlocal q
 q = 1
"


What system lets you do that? (See other thread about Windows not 
allowing that, because newline terminates the command even after ".) Is 
'>' a line continuation marker (like '...' in Python)?



so it should also work in IDLE.


I agree, and implied such on the tracker issue
http://bugs.python.org/issue19335

The question is "what does Idle do differently from the C level 
interpreter". The answer is that is subclasses the Python-coded 
code.InteractiveInterpreter. Call this II. II.runsource compiles 
*cumulative* source ultimately with the Python-coded 
codeop._maybe_compile, which returns a code object (source complete and 
valid) or None (source incomplete) or raises (source complete but not 
valid). The bug is seeing the three line input as 'complete but invalid' 
rather than as 'incomplete' (as the regular interpreter must).


To verify that this is not an Idle bug:
C:\Programs\Python33>python -m code
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 
bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> def a():
...  def b():
...   nonlocal c
  File "", line None
SyntaxError: no binding for nonlocal 'c' found

There is a bit more on the tracker.

--
Terry Jan Reedy

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


Re: Using "with" context handler, and catching specific exception?

2013-10-21 Thread Victor Hooi
Hi,

Thanks for the replies =).

Aha, good point about IOError encapsulating other things, I'll use 
FileNotFoundError, and also add in some other except blocks for the other ones.

And yes, I didn't use the exception object in my sample - I just sort. I'd 
probably be doing something like this.

logger.error("Some error message - %s" % e) 

So is the consensus then that I should wrap the "with" in a try-except block?

try: 
  with open('somefile.log', 'wb') as f: 
  f.write("hello there") 
except FileNotFoundError as e: 
logger.error("Uhoh, the file wasn't there - %s" % e) 

Cheers,
Victor

On Tuesday, 22 October 2013 14:04:14 UTC+11, Ben Finney  wrote:
> Victor Hooi  writes:
> 
> 
> 
> > try:
> 
> > with open('somefile.log', 'wb' as f:
> 
> > f.write("hello there")
> 
> > except IOError as e:
> 
> > logger.error("Uhoh, the file wasn't there").
> 
> 
> 
> IOError, as Steven D'Aprano points out, is not equivalent to “file not
> 
> found”. Also, you're not doing anything with the exception object, so
> 
> there's no point binding it to the name ‘e’.
> 
> 
> 
> What you want is the specific FileNotFoundError:
> 
> 
> 
> try:
> 
> with open('somefile.log', 'wb' as f:
> 
> f.write("hello there")
> 
> except FileNotFoundError:
> 
> logger.error("Uhoh, the file wasn't there").
> 
> 
> 
> See http://docs.python.org/3/library/exceptions.html#FileNotFoundError>.
> 
> 
> 
> -- 
> 
>  \“Choose mnemonic identifiers. If you can't remember what |
> 
>   `\mnemonic means, you've got a problem.” —Larry Wall |
> 
> _o__)  |
> 
> Ben Finney
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea.

2013-10-21 Thread Dave Angel
On 21/10/2013 17:19, Peter Cacioppi wrote:

> Just because the CPython implementation does something doesn't mean

If you're going to drop messages in here with no context, you'd be
better off just putting it in a bottle and tossing it into the sea. 

Include a quote from whomever you're responding to, and we might
actually take you seriously.  And of course, make sure you don't delete
the attribution.

-- 
DaveA


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


Re: Python Front-end to GCC

2013-10-21 Thread rusi
On Tuesday, October 22, 2013 1:59:36 AM UTC+5:30, Ned Batchelder wrote:
> On 10/21/13 4:14 PM, Mark Janssen wrote:
> 
> > On Mon, Oct 21, 2013 at 12:46 AM, Steven D'Aprano wrote:
> >> An optimizing JIT compiler can
> >> often produce much more efficient, heavily optimized code than a static
> >> AOT compiler,
> > This is horseshit.
> 
> Surely we can discuss this without resorting to swearing.

Thanks Ned for the intervention.
It is good to have 'interesting' and even 'hot' discussions.
Beyond a point they remain hot but not interesting
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-21 Thread Piet van Oostrum
Mark Janssen  writes:

>> No its not like those 'compilers' i dont really agree with a compiler 
>> generating C/C++ and saying its producing native code. I dont really believe 
>> its truely within the statement. Compilers that do that tend to put in alot 
>> of type saftey code and debugging internals at a high level to get things 
>> working in other projects i am not saying python compilers here i havent 
>> analysed enough to say this.
>
> Hmm, well what I'd personally find interesting from a computer science
> point of view is a app that will take a language specification in BNF
> (complete with keywords and all) and output C code which is then
> compiled to an executable as normal.  This is how a front-end should
> be designed.  A middle-layer for translating common language elements
> like lists, sets, etc, could make it easy.

A language specification in BNF is just syntax. It doesn't say anything
about semantics. So how could this be used to produce executable C code
for a program? BNF is used to produce parsers. But a parser isn't
sufficient.
-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using "with" context handler, and catching specific exception?

2013-10-21 Thread Ben Finney
Victor Hooi  writes:

> Aha, good point about IOError encapsulating other things, I'll use
> FileNotFoundError, and also add in some other except blocks for the
> other ones.

Or not; you can catch OSError, which is the parent of FileNotFoundError
http://docs.python.org/3/library/exceptions.html#exception-hierarchy>,
but don't assume in your code that it means anything more specific.

You should only catch specific exceptions if you're going to do
something specific with them. If all you want to do is log them and move
on, then catch a more general class and ask the exception object to
describe itself (by using it in a string context).


In versions of Python before 3.3, you have to catch EnvironmentError
http://docs.python.org/3.2/library/exceptions.html#EnvironmentError>
and then distinguish the specific errors by their ‘errno’ attribute
http://docs.python.org/3.2/library/errno.html>::

import errno

try:
with open('somefile.log', 'wb') as f:
f.write("hello there")
except EnvironmentError as exc:
if exc.errno == errno.ENOENT:
handle_file_not_found_error()
elif exc.errno == errno.EACCES:
handle_permission_denied()
elif exc.errno == errno.EEXIST:
handle_file_exists()
…
else:
handle_all_other_environment_errors()

That's much more clumsy, which is why it was improved in the latest
Python. If you can, code for Python 3.3 or higher.

-- 
 \ “Unix is an operating system, OS/2 is half an operating system, |
  `\Windows is a shell, and DOS is a boot partition virus.” —Peter |
_o__)H. Coffin |
Ben Finney

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


Re: Receive packet using socket

2013-10-21 Thread john pierce
Tom wrote:
BTW what I am trying to accomplish is easily done in hping3 using this comm=
and:
hping3 mtalk.google.com -S -p 5228=20

I just want those same kind of results using python so I can make an exe ou=
t of it.

Hi Tom,

Not sure if it's exactly what you're looking for, but I wrote a tcp syn scanner 
using raw sockets and another that uses scapy.  You can take a look at 
http://www.arti-sec.com/article/spse-module-2-lesson-4-syn-scanner-python.  You 
might take a look at scapy if you don't want to reinvent the wheel like I did.  
scapy is definitely worth a look if you want something powerfull and aren't 
interested in reinventing the wheel.

Regarding your code/initial question, I think it may be that the server is 
resetting the connection when it receives the string 'Data' as opposed to 
something that looks like what it expects. 


--=  Posted using GrabIt  =
--=  Binary Usenet downloading made easy =-
-=  Get GrabIt for free from http://www.shemes.com/  =-

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


Re: Python Front-end to GCC

2013-10-21 Thread Mark Janssen
> A language specification in BNF is just syntax. It doesn't say anything
> about semantics. So how could this be used to produce executable C code
> for a program? BNF is used to produce parsers. But a parser isn't
> sufficient.

A C program is just syntax also.  How does the compiler generate
executable machine code?  Extrapolate into a Python front-end to C.

-- 
MarkJ
Tacoma, Washington
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Front-end to GCC

2013-10-21 Thread Dave Angel
On 22/10/2013 00:24, Mark Janssen wrote:

>> A language specification in BNF is just syntax. It doesn't say anything
>> about semantics. So how could this be used to produce executable C code
>> for a program? BNF is used to produce parsers. But a parser isn't
>> sufficient.
>
> A C program is just syntax also.  How does the compiler generate
> executable machine code?  Extrapolate into a Python front-end to C.
>

Did you even read the paragraph you quoted above?  The BNF specification
does NOT completely describe a language, it only defines its syntax.  So
if the only thing you knew about C was its BNF, you could certainly not
write a C compiler.  And neither could anyone else.  Fortunately for the
C community, the language specification included much more than a BNF
grammar.  At a minimum, you have to specify both the syntax and the
semantics.

All that has nothing to do with an actual program written in an
actually defined language, whether C or Python.

-- 
DaveA


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


Re: Python Front-end to GCC

2013-10-21 Thread Steven D'Aprano
On Mon, 21 Oct 2013 21:24:38 -0700, Mark Janssen wrote:

>> A language specification in BNF is just syntax. It doesn't say anything
>> about semantics. So how could this be used to produce executable C code
>> for a program? BNF is used to produce parsers. But a parser isn't
>> sufficient.
> 
> A C program is just syntax also.  How does the compiler generate
> executable machine code?  Extrapolate into a Python front-end to C.

Like every other language, C programs are certainly not *just* syntax. 
Here is some syntax:

&foo bar^ :=

What machine code should be produced? Right now, you should be saying 
"How the hell do I know? What does that line of code *do*???" and you 
would be right to ask that question.

Syntax on its own doesn't mean anything. You also need to know the 
*semantics* of the code, in other words, *what it means*. That knowledge 
is inherent to the compiler: a C compiler "understands" what C code 
means, a Pascal compiler "understands" Pascal code, a Forth compiler 
"understands" Forth.

Merely parsing code doesn't capture that understanding. Parsing a line 
like "foo <= bar" will give you something like this:

NAME "foo"
OPERATOR "<="
NAME "bar"
END_LINE

What does the operator "<=" actually do? What does "foo" represent? Is it 
a variable, a constant, a global, a local, something else? What are the 
rules for deciding whether a variable is in the local scope, a global 
scope, or something else? Does the language even have scopes?



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


Re: Animated PNG Vs Gif: 120fr 3D Python Powered Logo

2013-10-21 Thread Metallicow
Here is links to the apng/gif on ImageShack uploaded with the "Do Not Resize" 
option.
Checked/Views fine with default Firefox/Opera browsers.

Animated 3D Python Powered Logo
apng - 120frames 1/60 sec
http://img34.imageshack.us/img34/4717/f4l4.png

gif - 120frames about 1/10sec or as fast as it can go...
http://img35.imageshack.us/img35/4231/j29.gif
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: IDLE being too clever checking nonlocal declarations?

2013-10-21 Thread Steven D'Aprano
On Mon, 21 Oct 2013 23:26:28 -0400, Terry Reedy wrote:

> On 10/21/2013 7:52 PM, Steven D'Aprano wrote:
>> On Mon, 21 Oct 2013 15:51:56 -0400, Terry Reedy wrote:
>>
>>> On 10/21/2013 11:06 AM, Chris Angelico wrote:
 Try typing this into IDLE:

>>> def a():
   def b():
   nonlocal q
 SyntaxError: no binding for nonlocal 'q' found
>>>
>>> If you submit those three lines to Python from the command line, that
>>> is what you see.
>>
>> Arguably, that's also too strict,
> 
> As I quoted from the doc, it is an error for a program to contain a
> nonlocal with no referent. The reason is one only needs nonlocal to bind
> and unlike with 'global newname', it would be undefined where to do the
> binding.

Yep, I got that, but what I'm saying is that it is too strict to raise 
the exception at the point where it sees "nonlocal q". The CPython 
interpreter allows q to be defined inside function a but after function 
b, e.g. this is allowed:

def a():
def b():
nonlocal q
q += 1
q = 2  # <===


If IDLE and the code.py module requires q to be strictly defined before 
function b, then it is too strict. Your analysis of the bug as being in 
code.py seems plausible.



>> [steve@ando ~]$ python3.3 -c "def a():
>>>  def b():
>>>  nonlocal q
>>>  q = 1
>>> "
> 
> What system lets you do that? (See other thread about Windows not
> allowing that, because newline terminates the command even after ".) Is
> '>' a line continuation marker (like '...' in Python)?

Yes, sorry I should have said. That's bash, under Linux.

Here's another way:


steve@runes:~$ python3.3 -c "def a():^M  def b():^Mnonlocal q^M  
q=1^Mprint(a() is None)"
True


Still bash under Linux (a different machine), the ^M is *not* a pair of 
characters ^ followed by M but an actually newline, generated by typing 
Ctrl-V Enter (that's the ENTER key, not the letters E n t e r).

In theory I should be able to get something working with \n escapes 
instead of ^M, but I can't get it working. But I'm not an expect at bash's 
arcane rules for quoting and escaping special characters.



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


Re: Python was designed (was Re: Multi-threading in Python vs Java)

2013-10-21 Thread Chris Angelico
On Tue, Oct 22, 2013 at 2:19 PM, rusi  wrote:
> On Tuesday, October 22, 2013 8:25:58 AM UTC+5:30, Peter Cacioppi wrote:
>
> Guess-who said:
>
>> "but it's "ugly", by which I mean it is hard to use, error prone, and not
>> easily maintained."
>>
>> OK, I see the problem. What you call "ugly" is really just objectively bad.
>
> You continue to not attribute quotes.
>
> What user agent/group are you using?

I don't know what headers come through on comp.lang.python, but on the
mailing list, I can see some clear fingerprints that it's the one so
many of us hate...

Message-ID: <6f511c0b-c5fa-4307-9a2a-cb73a1768...@googlegroups.com>
Complaints-To: groups-ab...@google.com

Though I don't think the abuse address would do much with complaints
regarding citation courtesy :)

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


Re: IDLE being too clever checking nonlocal declarations?

2013-10-21 Thread Chris Angelico
On Tue, Oct 22, 2013 at 4:57 PM, Steven D'Aprano  wrote:
> Yep, I got that, but what I'm saying is that it is too strict to raise
> the exception at the point where it sees "nonlocal q". The CPython
> interpreter allows q to be defined inside function a but after function
> b, e.g. this is allowed:
>
> def a():
> def b():
> nonlocal q
> q += 1
> q = 2  # <===
>
>
> If IDLE and the code.py module requires q to be strictly defined before
> function b, then it is too strict. Your analysis of the bug as being in
> code.py seems plausible.

Yeah. I came across this as I was knocking together a test for
something else, and my work-around was to define the inner function as
just "pass", and then go back and edit in the nonlocal declaration
after adding the assignment outside. The only problem is that it's
syntax-checking something that's only half-entered, and is bombing on
it - thus stopping you from typing in the bit that would make it
valid.

Thanks Terry for the extra info on the tracker issue.

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


Re: Animated PNG Vs Gif: 120fr 3D Python Powered Logo

2013-10-21 Thread Terry Reedy

On 10/22/2013 1:28 AM, Metallicow wrote:

Here is links to the apng/gif on ImageShack uploaded with the "Do Not Resize" 
option.
Checked/Views fine with default Firefox/Opera browsers.

Animated 3D Python Powered Logo
apng - 120frames 1/60 sec
http://img34.imageshack.us/img34/4717/f4l4.png


Neat: I would actually have the rotation slower, but still smoothed.


gif - 120frames about 1/10sec or as fast as it can go...
http://img35.imageshack.us/img35/4231/j29.gif


I can see the jerking.

--
Terry Jan Reedy

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