Re: Python Scalability TCP Server + Background Game

2014-01-18 Thread Chris Angelico
On Sat, Jan 18, 2014 at 6:44 PM,   wrote:
>> Quick smoke test. How big are your requests/responses? You mention
>>
>> REST, which implies they're going to be based on HTTP. I would expect
>>
>> you would have some idea of the rough size. Multiply that by 50,000,
>>
>> and see whether your connection can handle it. For instance, if you
>>
>> have a 100Mbit/s uplink, supporting 50K requests/sec means your
>>
>> requests and responses have to fit within about 256 bytes each,
>>
>> including all overhead. You'll need a gigabit uplink to be able to
>>
>> handle a 2KB request or response, and that's assuming perfect
>>
>> throughput. And is 2KB enough for you?
>>
>>
>>
>> ChrisA
>
> My assumption is that there will be mostly reads and some writes; maybe in 
> the order of 80-20%. There is a time element in the game, which forces 
> player's entity to update on-demand. This is part of the reason why I wanted 
> the server to be able to handle so many reques, so that it could handle the 
> read part without having any caching layer.
>

(You're using Google Groups, which means your replies are
double-spaced and your new text is extremely long lines. Please fix
this, either by the fairly manual job of fixing every post you make,
or the simple method of switching to a better client. Thanks.)

My point was just about the REST API, nothing else. You have to handle
a request and a response for every API call. Whether they're reads or
writes, you need to receive an HTTP request and send an HTTP response
for each one. In order to support the 50k requests per second you hope
for, you would have to handle 50k requests coming in and 50k responses
going out. To do that, you would need - at a very VERY rough estimate
- a maximum request size of 2KB and a gigabit internet connection
(which is expensive). No further calculations are worth pursuing if
you can't handle those requests and responses.

(And small requests tend to be more expensive than large ones. Since
you'll need a minimum of >SYN, ACK, >DATA, FIN,
ACK in order to transmit and receive one single packet's
worth of data each way, you're looking at roughly 8 packets minimum
for a one-byte message and one-byte response. But at a very very rough
estimate, 2KB each direction is the most you can sustain.)

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


Re: How to write this as a list comprehension?

2014-01-18 Thread Peter Otten
Piet van Oostrum wrote:

> Hi,
> 
> I am looking for an elegant way to write the following code as a list
> comprehension:
> 
> labels = []
> for then, name in mylist:
> _, mn, dy, _, _, _, wd, _, _ = localtime(then)
> labels.append(somefunc(mn, day, wd, name))
> 
> So mylist is a list of tuples, the first member of the tuple is a time
> (as epoch offset) and I neeed to apply a function on some fields of the
> localtime of it.
> 
> I could define a auxiliary function like:
> 
> def auxfunc(then, name):
> _, mn, dy, _, _, _, wd, _, _ = localtime(then)
> return somefunc(mn, day, wd, name)
> 
> and then use
> [auxfunc(then, name) for then, name in mylist]
> 
> or even
> [auxfunc(*tup) for tup in mylist]
> 
> But defining the auxfunc takes away the elegance of a list comprehension.
> I would like to integrate the unpacking of localtime() and calling
> somefunc within the list comprehension, but I don't see a simple way to do
> that.
> 
> somefunc(mn, day, wd, name) for _, mn, dy, _, _, _, wd, _, _ in
> [localtime(then)] (i.e. using a list comprehension on a one element list
> to do the variable shuffling) works but I don't find that very elegant.
> 
> labels = [somefunc(mn, day, wd, name)
> for then, name in mylist
> for _, mn, dy, _, _, _, wd, _, _ in [localtime(then)]]
> 
> Python misses a 'where' or 'let'-like construction as in Haskell.
> 
> Anybody has a more elegant solution?

Options I can think of: 

You could do it in two steps...

time_name_pairs = ((localtime(then), name) for then, name in mylist)
labels = [somefunc(t.tm_mon, t.tm_mday, t.tm_wday, name) 
  for t, name in time_name_pairs]

...or you could inline the helper function...

mon_mday_wday = operator.attrgetter("tm_mon", "tm_day", "tm_wday")
labels = [somefunc(*mon_mday_wday(localtime(then)), name=name) 
  for then, name in mylist]

-- but both seem less readable than the classical for-loop.

What would a list-comp with `let` or `where` look like? Would it win the 
beauty contest against the loop?

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


Re: doctests compatibility for python 2 & python 3

2014-01-18 Thread Albert-Jan Roskam

On Fri, 1/17/14, Terry Reedy  wrote:

 Subject: Re: doctests compatibility for python 2 & python 3
 To: python-list@python.org
 Date: Friday, January 17, 2014, 10:10 PM
 
 On 1/17/2014 7:14 AM, Robin Becker
 wrote:
 
 > I tried this approach with a few more complicated
 outcomes and they fail
 > in python2 or 3 depending on how I try to render the
 result in the doctest.
 
 I never got how you are using doctests. There were certainly
 not meant for heavy-duty unit testing, but for testing
 combined with explanation. Section 26.2.3.7. (in 3.3)
 Warnings warns that they are fragile to even single char
 changes and suggests == as a workaround, as 'True' and
 'False' will not change. So I would not reject that option.
 

=> I used doctests in .txt files and I converted ALL of them when I wanted 
to make my code work for both Python 2 and 3. I tried to fix something like a 
dozen of them so they'd work in Python 2.7 and 3,3. but I found it just too 
cumbersome and time consuming. The idea of doctest is super elegant, but it is 
really only meant for testable documentation (maybe with sphinx). If you'd put 
all the (often boring, e.g. edge cases) test cases in docstrings, the .py file 
will look very cluttered. One thing that I missed in unittest was Ellipsis, 
but: https://pypi.python.org/pypi/gocept.testing/1.6.0 offers assertEllipsis 
and other useful stuff.

Albert-Jan


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


Re: numpy.where() and multiple comparisons

2014-01-18 Thread Peter Otten
John Ladasky wrote:

> On Friday, January 17, 2014 6:16:28 PM UTC-8, duncan smith wrote:
> 
>>  >>> a = np.arange(10)
>>  >>> c = np.where((2 < a) & (a < 7))
>>  >>> c
>> (array([3, 4, 5, 6]),)
> 
> Nice!  Thanks!
> 
> Now, why does the multiple comparison fail, if you happen to know?

2 < a < 7

is equivalent to

2 < a and a < 7

Unlike `&` `and` cannot be overridden (*), so the above implies that the 
boolean value bool(2 < a) is evaluated. That triggers the error because the 
numpy authors refused to guess -- and rightly so, as both implementable 
options would be wrong in a common case like yours.

(*) I assume overriding would collide with short-cutting of boolean 
expressions.

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


Re: Guessing the encoding from a BOM

2014-01-18 Thread Gregory Ewing

Chris Angelico wrote:

On Fri, Jan 17, 2014 at 8:10 PM, Mark Lawrence  wrote:

Every time I see it I picture Inspector

Clouseau, "A BOM!!!" :)


Special delivery, a berm! Were you expecting one?


A berm? Is that anything like a shrubbery?

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


Re: How to write this as a list comprehension?

2014-01-18 Thread Piet van Oostrum
Rustom Mody  writes:

> On Saturday, January 18, 2014 4:49:55 AM UTC+5:30, Piet van Oostrum wrote:
[...]
>
>> Python misses a 'where' or 'let'-like construction as in Haskell.
>
> +1
> Yes Ive often been bitten by the lack of a 'comprehension-let'

If it used only in a comprehension as in my example you can write instead of 
'where vars = expr':
   for vars in [expr], unnecessarily construction a one element list.
If there would be a syntax like:
   for vars = expr
this could be avoided.
>
> Something like this is possible??
>
>
> [somefunc(mn,day,wd,name) for (_, mn,dy,_,_,_,wd,_,_), name) in
> [localtime(then), name for then, name in mylist]]
It works modulo some corrections in the parentheses:

[somefunc(mn,day,wd,name) for (_, mn,dy,_,_,_,wd,_,_), name in
  [(localtime(then), name) for then, name in mylist]]
but I find that hardly more elegant.
-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Guessing the encoding from a BOM

2014-01-18 Thread Chris Angelico
On Sat, Jan 18, 2014 at 8:41 PM, Gregory Ewing
 wrote:
> Chris Angelico wrote:
>>
>> On Fri, Jan 17, 2014 at 8:10 PM, Mark Lawrence 
>> wrote:
>>
>> Every time I see it I picture Inspector
>>>
>>> Clouseau, "A BOM!!!" :)
>>
>>
>> Special delivery, a berm! Were you expecting one?
>
>
> A berm? Is that anything like a shrubbery?

http://www.youtube.com/watch?v=GLDvtpSC_98

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


Re: How to write this as a list comprehension?

2014-01-18 Thread Matěj Cepl
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 2014-01-17, 23:19 GMT, you wrote:
> But defining the auxfunc takes away the elegance of a list 
> comprehension.

Au contraire! Remember, that brevity is the sister of talent.  

I would definitively vote for 

labels = [make_label(then, name) for then, name in mylist]

(always use descriptive names of functions and variables; 
auxfunc is a short way to the hell)

Beauty of the list comprehensions is that they show nicely what 
list is being processed, how it is filtered (if at all), and 
what we do with each element of the generated list. Anything you 
add to this simplicity is wrong. Whenever you start to feel you 
are missing some methods how to stuff more commands into 
a comprehension (or for example multiple embedded ones), you 
should start new function.

The same rule applies here as with any other lambda function 
(because these are in fact lambda functions): the best way how 
to write lambda is to write algorithm somewhere on the side, 
describe what this function does in one word, then add `def` in 
front of that name, and use so created named function instead.

Best,

Matěj

-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.22 (GNU/Linux)

iD8DBQFS2l4X4J/vJdlkhKwRAjEgAJ4n1OuANYlVFzlgBZ0f1uMhO/t36gCfdFjE
VmYDJ+F7aN0khzvlY50i0iA=
=Trcc
-END PGP SIGNATURE-
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Scalability TCP Server + Background Game

2014-01-18 Thread phiwer
> (You're using Google Groups, which means your replies are
> 
> double-spaced and your new text is extremely long lines. Please fix
> 
> this, either by the fairly manual job of fixing every post you make,
> 
> or the simple method of switching to a better client. Thanks.)
> 
> 
> 
> My point was just about the REST API, nothing else. You have to handle
> 
> a request and a response for every API call. Whether they're reads or
> 
> writes, you need to receive an HTTP request and send an HTTP response
> 
> for each one. In order to support the 50k requests per second you hope
> 
> for, you would have to handle 50k requests coming in and 50k responses
> 
> going out. To do that, you would need - at a very VERY rough estimate
> 
> - a maximum request size of 2KB and a gigabit internet connection
> 
> (which is expensive). No further calculations are worth pursuing if
> 
> you can't handle those requests and responses.
> 
> 
> 
> (And small requests tend to be more expensive than large ones. Since
> 
> you'll need a minimum of >SYN, ACK, >DATA, FIN,
> 
> ACK in order to transmit and receive one single packet's
> 
> worth of data each way, you're looking at roughly 8 packets minimum
> 
> for a one-byte message and one-byte response. But at a very very rough
> 
> estimate, 2KB each direction is the most you can sustain.)
> 
> 
> 
> ChrisA


Aha, thanks for the info.

But the assumptions you are making does not answer the question.

And the question you raise, although important, is more a financial one, 
not really relevant to the questions I posed.

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


python to enable javascript , tried selinium, ghost, pyQt4 already

2014-01-18 Thread Jaiprakash Singh
hi,

 can you please suggest me some method for  study so that i can scrap a 
site having JavaScript behind it 


 i have tried selenium, ghost, pyQt4,  but it is slow and as a am working with 
thread it sinks my ram memory very fast.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to write this as a list comprehension?

2014-01-18 Thread Alain Ketterlin
Piet van Oostrum  writes:

[...]
> I could define a auxiliary function like:
>
> def auxfunc(then, name):
> _, mn, dy, _, _, _, wd, _, _ = localtime(then)
> return somefunc(mn, day, wd, name)
>
> and then use 
> [auxfunc(then, name) for then, name in mylist]

[...]

> labels = [somefunc(mn, day, wd, name) 
> for then, name in mylist
> for _, mn, dy, _, _, _, wd, _, _ in [localtime(then)]]
>
> Python misses a 'where' or 'let'-like construction as in Haskell.

"let x = v in e" really is (lambda x:e)(v)

In your case:

[ (lambda na,ti : somefunc(ti[1],ti[2],ti[6],na))(name,localtime(then))
  for then,name in mylist ]

Warning: absolutely untested (not even syntax-checked).

You may also use *localtime(...) and keep underscores.

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


Re: Python Scalability TCP Server + Background Game

2014-01-18 Thread Asaf Las
On Wednesday, January 15, 2014 8:37:25 PM UTC+2, phi...@gmail.com wrote:
> My problem is as follows: 
> 
> 2) The network layer of the game server runs a separate process as well, 
> and my intention was to use gevent or tornado (http://nichol.as/asynchronous-
>servers-in-python).
> 3) The game server has a player limit of 5. My requirement/desire is to 
> be able to serve 50k requests per second 
> 4) The game is not a real-time based game, but is catered towards the web.
> Due to this information, I have developed the initial server using netty in 
> java. I would, however, rather develop the server using python,... and then 
> use python for the frontend. ...

do you have references to implementations where python was used as frontend for 
such traffic load? 

you can have a look to this group for numbers
https://groups.google.com/forum/#!forum/framework-benchmarks

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


Re: Python Scalability TCP Server + Background Game

2014-01-18 Thread phiwer
Den lördagen den 18:e januari 2014 kl. 13:13:47 UTC+1 skrev Asaf Las:
> On Wednesday, January 15, 2014 8:37:25 PM UTC+2, phi...@gmail.com wrote:
> 
> > My problem is as follows: 
> 
> > 
> 
> > 2) The network layer of the game server runs a separate process as well, 
> 
> > and my intention was to use gevent or tornado 
> > (http://nichol.as/asynchronous-
> 
> >servers-in-python).
> 
> > 3) The game server has a player limit of 5. My requirement/desire is to 
> 
> > be able to serve 50k requests per second 
> 
> > 4) The game is not a real-time based game, but is catered towards the web.
> 
> > Due to this information, I have developed the initial server using netty in 
> 
> > java. I would, however, rather develop the server using python,... and then 
> 
> > use python for the frontend. ...
> 
> 
> 
> do you have references to implementations where python was used as frontend 
> for such traffic load? 
> 
> 
> 
> you can have a look to this group for numbers
> 
> https://groups.google.com/forum/#!forum/framework-benchmarks
> 
> 
> 
> Asaf

Yes I've looked at those charts, and that was one of the reasons why I decided
to go with netty for the back-end (although I'm probing to see if python 
possibly could match in some way, which I haven't thought of yet...).

With regards to front-end, I haven't fully decided upon which framework to use.
It's easier to scale the front-end, however, given that the problem of
locking game state is not present in this logical part of the architecture.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Scalability TCP Server + Background Game

2014-01-18 Thread Mark Lawrence

On 18/01/2014 12:40, phi...@gmail.com wrote:

[snip the stuff I can't help with]

Here's the link you need to sort the problem with double spacing from 
google groups https://wiki.python.org/moin/GoogleGroupsPython


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

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


Re: Python 3.x adoption

2014-01-18 Thread beliavsky
On Friday, January 17, 2014 6:03:45 PM UTC-5, Terry Reedy wrote:
> On 1/17/2014 5:16 PM, beliav...@aol.com wrote:
 
>  > Python 2 and 3 are incompatible in ways that do not apply to Fortran 
> 
>  > standards pre- and post- F77.
> 
> 
> 
> As stated above, I disagree with respect to pre-F77 and F77. Did you 
> 
> actually program in both, as I did?
> 
> 
> 
> -- 
> 
> Terry Jan Reedy

I should have written "F77 and post F77". I have programmed in Fortran 77, 90, 
and 95.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] advice and comment wanted on first tkinter program

2014-01-18 Thread Jean Dupont
Op vrijdag 17 januari 2014 22:40:42 UTC+1 schreef Terry Reedy:
> On 1/17/2014 8:20 AM, Jean Dupont wrote:
> 
> > Dear all,
> 
> > I made a simple gui with tkinter. I can imagine there are things which I
> 
> > did which are "not optimal". So what I ask is to comment on my code
> 
> > preferable with snippets of code which show how to do improve my code.
> 
> > #!/usr/bin/env python
> 
> > import Tkinter
> 
> 
> 
> 1. import Tkinter as tk
> 
> 
> 
> Besides saving a bit of writing and reading time later, this makes any 
> 
> future conversion to 3.x easier.
> 
> 
> 
> import tkinter as tk
> 
> 
> 
> 2. add a few spaces to demarcate blocks of code.
> 
> 
> 
> > import time
> 
> > import RPi.GPIO as GPIO
> 
> 
> 
> 2. add a few spaces to demarcate blocks of code, such as here
> 
> 
> 
> > GPIO.setmode(GPIO.BOARD)
> 
> > GPIO.setup(26,GPIO.OUT)
> 
> > GPIO.setup(24,GPIO.OUT)
> 
> > #hardware : connect 2 leds:
> 
> > #board-pin 26 on/off led; control with buttons
> 
> > #board-pin 24 led with pwm dimming and frequency; control via sliders
> 
> 
> 
> and here
> 
> 
> 
> > top = Tkinter.Tk()
> 
> > top.geometry("600x400+310+290")
> 
> 
> 
> This looks strange somehow, but if it works...
> 
> 
> 
> 
> 
> > label1 = Label(top,relief=RAISED,bg =
> 
> > "#EFF980",font=("Helvetica",14),height = 1, width = 15)
> 
> 
> 
> In calls, put spaces after , but not before and after =.
> 
> For other suggestions, see
> 
> http://www.python.org/dev/peps/pep-0008/
> 
> 
> 
> I suspect that the above is one line in your code and the bad wrapping a 
> 
> result of mis-spacing. The following is also one line, but easer to read 
> 
> as spaces separate argument chunks
> 
> 
> 
> label1 = Label(top, relief=RAISED, bg="#EFF980", font=("Helvetica",14), 
> 
> height=1, width=15)
> 
> 
> 
> and the wrapping, if any, does not break up an arg chunk.
> 
> 
> 
> Some people advocate defining an App class, but Tk and tkinter, even 
> 
> though object method based, allow the straightforward imperative style 
> 
> you have used.
> 
> 
> 
> I agree with Peter: "First and foremost a program has to do what the 
> 
> author wants it to do. Everything else is secondary." But a bit of 
> 
> styling will make reading and changing easier.
> 
> 
> 
> -- 
> 
> Terry Jan Reedy

Thanks Peter and Terry Jan for the useful suggestions. One thing which I find a 
bit weird: when asking for Python-help concerning raspberry pi code or 
problems, a lot of people don't seem to be interested in helping out, that's of 
course their choice, but maybe they don't seem to be aware the raspberry pi is 
often the motivation for starting to learn to program in Python. And as such 
such a reaction is a bit disappointing.

kind regards,
jean
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] advice and comment wanted on first tkinter program

2014-01-18 Thread Oscar Benjamin
On 18 January 2014 14:52, Jean Dupont  wrote:
>
> Thanks Peter and Terry Jan for the useful suggestions. One thing which I find 
> a bit weird: when asking for Python-help concerning raspberry pi code or 
> problems, a lot of people don't seem to be interested in helping out, that's 
> of course their choice, but maybe they don't seem to be aware the raspberry 
> pi is often the motivation for starting to learn to program in Python. And as 
> such such a reaction is a bit disappointing.

Hi Jean,

What makes you say that? Did you previously ask questions about
Rasberry Pi code on this list?

If you did I wouldn't have answered those questions because I've never
used a Raspberry Pi and know nothing about them (except that they
encourage using Python somehow). I think that there's actually a list
that is specifically for Raspberry Pi Python questions that might be
more helpful although I don't know what it is...


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


Re: How to write this as a list comprehension?

2014-01-18 Thread Rustom Mody
On Saturday, January 18, 2014 2:06:29 PM UTC+5:30, Peter Otten wrote:

> Options I can think of: 

> You could do it in two steps...

> time_name_pairs = ((localtime(then), name) for then, name in mylist)
> labels = [somefunc(t.tm_mon, t.tm_mday, t.tm_wday, name) 
>   for t, name in time_name_pairs]

> ...or you could inline the helper function...

> mon_mday_wday = operator.attrgetter("tm_mon", "tm_day", "tm_wday")
> labels = [somefunc(*mon_mday_wday(localtime(then)), name=name) 
>   for then, name in mylist]

> -- but both seem less readable than the classical for-loop.

> What would a list-comp with `let` or `where` look like? Would it win the 
> beauty contest against the loop?

For me this is neat

[somefunc(mn,day,wd,name) for (then, name) in mylist let (_,mn,dy,_,_,_,wd,_,_) 
= localtime(then)]
   
Others may not find it so!

See it across > 1 line (as I guess it will come after being posted!) and its 
not so neat.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to write this as a list comprehension?

2014-01-18 Thread Jussi Piitulainen
Rustom Mody writes:

> On Saturday, January 18, 2014 2:06:29 PM UTC+5:30, Peter Otten wrote:
>
> > What would a list-comp with `let` or `where` look like? Would it
> > win the beauty contest against the loop?
> 
> For me this is neat
> 
> [somefunc(mn,day,wd,name) for (then, name) in mylist let 
> (_,mn,dy,_,_,_,wd,_,_) = localtime(then)]
>
> Others may not find it so!
> 
> See it across > 1 line (as I guess it will come after being posted!)
> and its not so neat.

I would write that on three lines anyway, properly indented:

  [ somefunc(mn,day,wd,name)
for (then, name) in mylist
let (_,mn,dy,_,_,_,wd,_,_) = localtime(then) ]

It could be made to use existing keywords:

  [ somefunc(mn,day,wd,name)
for (then, name) in mylist
with localtime(then) as (_,mn,dy,_,_,_,wd,_,_) ]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] advice and comment wanted on first tkinter program

2014-01-18 Thread Mark Lawrence

On 18/01/2014 15:12, Oscar Benjamin wrote:

On 18 January 2014 14:52, Jean Dupont  wrote:


Thanks Peter and Terry Jan for the useful suggestions. One thing which I find a 
bit weird: when asking for Python-help concerning raspberry pi code or 
problems, a lot of people don't seem to be interested in helping out, that's of 
course their choice, but maybe they don't seem to be aware the raspberry pi is 
often the motivation for starting to learn to program in Python. And as such 
such a reaction is a bit disappointing.


Hi Jean,

What makes you say that? Did you previously ask questions about
Rasberry Pi code on this list?

If you did I wouldn't have answered those questions because I've never
used a Raspberry Pi and know nothing about them (except that they
encourage using Python somehow). I think that there's actually a list
that is specifically for Raspberry Pi Python questions that might be
more helpful although I don't know what it is...


Oscar



As Python is meant to be cross platform i think it's pretty much 
irrelevant that Raspberry Pi is mentioned.  It's far more likely that 
people don't respond as questions are asked about specific libraries 
which they haven't used.


Neither does it help when considering Jean's last post that the final 
paragraph shows as one line in Thunderbird on Windows and over 60% is 
simply blank lines.  No guesses as to how he's posting.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

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


Re: How to write this as a list comprehension?

2014-01-18 Thread Piet van Oostrum
Alain Ketterlin  writes:

> Piet van Oostrum  writes:
> [...]
>> Python misses a 'where' or 'let'-like construction as in Haskell.
>
> "let x = v in e" really is (lambda x:e)(v)
>
You are right, but it is a lot less readable IMHO.
-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Python Simple program

2014-01-18 Thread indar kumar
Hello, I am a newbie. Can somebody help me write the code for following program?


Write a program that takes student grades and prints out the GPA. The 
information is input, one student per line in the format:...
The number of students is not known in advance. You should prompt the user for 
more until they enter an empty line. The number of courses per student varies 
and is also not known in advance. You should read as many grades as are entered 
on the line.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python to enable javascript , tried selinium, ghost, pyQt4 already

2014-01-18 Thread Denis McMahon
On Sat, 18 Jan 2014 03:54:17 -0800, Jaiprakash Singh wrote:

> can you please suggest me some method for  study so that i can
> scrap a site having JavaScript behind it

Please expand upon the requirement, are you trying to:

a) replace server side javascript with server side python, or
b) replace client side javascript with server side python, or
c) replace client side javascript with client side python, or
d) something else?

(c) is not possible (you can't guarantee that all clients will have 
python, or that there will be a mechanism for calling it from your 
webpages), (b) doesn't make a lot of sense (you'll be trading cpu in the 
client for cpu in the server + network bandwidth and latency).

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Simple program

2014-01-18 Thread Chris Angelico
On Sun, Jan 19, 2014 at 5:00 AM, indar kumar  wrote:
> Hello, I am a newbie. Can somebody help me write the code for following 
> program?
>
>
> Write a program that takes student grades and prints out the GPA. The 
> information is input, one student per line in the format:  
>   ...
> The number of students is not known in advance. You should prompt the user 
> for more until they enter an empty line. The number of courses per student 
> varies and is also not known in advance. You should read as many grades as 
> are entered on the line.

No.

This is homework, and you should do it yourself - otherwise you are
cheating yourself, cheating on your course, and ultimately, cheating
an employer by making him/her think you know how to do something when
you don't.

If you write the code yourself and then have questions, then by all
means, bring those questions to us! We're happy to help you learn. But
that's quite different from outright doing your homework for you.

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


Re: python to enable javascript , tried selinium, ghost, pyQt4 already

2014-01-18 Thread Chris Angelico
On Sat, Jan 18, 2014 at 10:54 PM, Jaiprakash Singh
 wrote:
> hi,
>
>  can you please suggest me some method for  study so that i can scrap a 
> site having JavaScript behind it
>
>
>  i have tried selenium, ghost, pyQt4,  but it is slow and as a am working 
> with thread it sinks my ram memory very fast.

Do you mean "scrape"? You're trying to retrieve the displayed contents
of a web page that uses JavaScript? If so, that's basically impossible
without actually executing the JS code, which means largely
replicating the web browser.

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


Re: Python Simple program

2014-01-18 Thread Roy Smith
In article ,
 indar kumar  wrote:

> Hello, I am a newbie. Can somebody help me write the code for following 
> program?
> 
> 
> Write a program that takes student grades and prints out the GPA. The 
> information is input, one student per line in the format:  
>   ...
> The number of students is not known in advance. You should prompt the user 
> for more until they enter an empty line. The number of courses per student 
> varies and is also not known in advance. You should read as many grades as 
> are entered on the line.

This sounds like a homework problem for a basic programming course.

Rather than write your program for you, let me give you a few broad 
hints.  You're going to need to call raw_imput() in a loop to read in 
your data, then use split() to break the line up into fields, and 
another loop to iterate over the individual grades.

See what progress you can make with that, and if you get stuck, come 
back with whatever code you've written so far, and more specific 
questions.
-- 
https://mail.python.org/mailman/listinfo/python-list


question about input() and/or raw_input()

2014-01-18 Thread Roy Smith
Pardon me for being cynical, but in the entire history of the universe, 
has anybody ever used input()/raw_input() for anything other than a 
homework problem?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: question about input() and/or raw_input()

2014-01-18 Thread Mark Lawrence

On 18/01/2014 18:30, Roy Smith wrote:

Pardon me for being cynical, but in the entire history of the universe,
has anybody ever used input()/raw_input() for anything other than a
homework problem?



Not me personally.  I guess raw_input must have been used somewhere at 
some time for something, or it would have been scrapped in Python 3, not 
renamed to input.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

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


Re: Python Simple program

2014-01-18 Thread indar kumar
On Saturday, January 18, 2014 11:00:47 AM UTC-7, indar kumar wrote:
> Hello, I am a newbie. Can somebody help me write the code for following 
> program?
> 
> 
> 
> 
> 
> Write a program that takes student grades and prints out the GPA. The 
> information is input, one student per line in the format:  
>   ...
> 
> The number of students is not known in advance. You should prompt the user 
> for more until they enter an empty line. The number of courses per student 
> varies and is also not known in advance. You should read as many grades as 
> are entered on the line.



Hello, I think I just need one loop not separate loops. One while loop should 
be enough. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: question about input() and/or raw_input()

2014-01-18 Thread Emile van Sebille

On 01/18/2014 10:30 AM, Roy Smith wrote:

Pardon me for being cynical, but in the entire history of the universe,
has anybody ever used input()/raw_input() for anything other than a
homework problem?


Yes - routinely.

Emile



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


Re: question about input() and/or raw_input()

2014-01-18 Thread Peter Otten
Roy Smith wrote:

> Pardon me for being cynical, but in the entire history of the universe,
> has anybody ever used input()/raw_input() for anything other than a
> homework problem?

I use it for pointless throwaway tools, sometimes via the cmd module, 
sometimes directly. 

I like that you can add tab-completion.

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


Re: Python Simple program

2014-01-18 Thread Roy Smith
In article <60955b74-7bc8-4c72-94e1-849015985...@googlegroups.com>,
 indar kumar  wrote:

> On Saturday, January 18, 2014 11:00:47 AM UTC-7, indar kumar wrote:
> > Hello, I am a newbie. Can somebody help me write the code for following 
> > program?
> > 
> > 
> > 
> > 
> > 
> > Write a program that takes student grades and prints out the GPA. The 
> > information is input, one student per line in the format:  
> >   ...
> > 
> > The number of students is not known in advance. You should prompt the user 
> > for more until they enter an empty line. The number of courses per student 
> > varies and is also not known in advance. You should read as many grades as 
> > are entered on the line.
> 
> 
> 
> Hello, I think I just need one loop not separate loops. One while loop should 
> be enough. 

If you're going to accept multiple lines of input (one line per 
student), and multiple grades on each line, you're going to need two 
loops.  One loop iterates over the students, the other loop iterates 
over the various grades for each student.

Any program is going to have several phases.  Generally, you:

1) Read in the data

2) Process the data in some way

3) Print out the results

In your case, the processing will be converting the grades to numbers 
(here in the US, we generally assign grades as A=4, B=3, C=2, D=1, F=0, 
but that may differ where you are) and computing the average.

But, start simple.  Write the part of the program which accepts all the 
input first, and just prints it back out, so you know you read it in 
properly.  Once you're sure you've got that working, move on to the next 
phase.  I've been doing this for a long time, and that's still the way I 
attack any new problem.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re[2]: [newbie] advice and comment wanted on first tkinter program

2014-01-18 Thread Grawburg
The Raspberry Pi is exactly what got me started with Python. I'm at 
medium-sized science museum and used the Pi, Python, & tkinter to introduce 
kids to programming & Linux this past summer.

Jean, feel free to contact me off-line for my experience with all three.


Brian Grawburg
Wilson, NC


-Original Message- 
> From: "Oscar Benjamin"  
> To: "Jean Dupont"  
> Cc: "Python List"  
> Date: 01/18/14 10:13 AM 
> Subject: Re: [newbie] advice and comment wanted on first tkinter program 
> 
> On 18 January 2014 14:52, Jean Dupont  wrote:
> >
> > Thanks Peter and Terry Jan for the useful suggestions. One thing which I 
> > find a bit weird: when asking for Python-help concerning raspberry pi code 
> > or problems, a lot of people don't seem to be interested in helping out, 
> > that's of course their choice, but maybe they don't seem to be aware the 
> > raspberry pi is often the motivation for starting to learn to program in 
> > Python. And as such such a reaction is a bit disappointing.
> 
> Hi Jean,
> 
> What makes you say that? Did you previously ask questions about
> Rasberry Pi code on this list?
> 
> If you did I wouldn't have answered those questions because I've never
> used a Raspberry Pi and know nothing about them (except that they
> encourage using Python somehow). I think that there's actually a list
> that is specifically for Raspberry Pi Python questions that might be
> more helpful although I don't know what it is...
> 
> 
> Oscar
> -- 
> https://mail.python.org/mailman/listinfo/python-list

-- 
The truth will set you free . . .but first it will infuriate you.




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


Re: Porting c extension - PyBuffer_New() deprecated in python3. What's the replacement?

2014-01-18 Thread Mark Heieis

Stefan,

Thank-you for the reply. I hadn't considered cpython, unfortunately the 
extension is too large a project to port at the moment. I ended up 
replacing the PyBuffer_New() segment with malloc() and passing back an 
object from PyByteArray_FromStringAndSize(). It seems to work.


mrh.

On 2014-01-11 01:10, Stefan Behnel wrote:

Mark Heieis, 11.01.2014 06:47:

I need to convert the following existing c extension code to support Python 3.

// --- existing code --

 // PyBuffer_New() deprecated in python3
 if (!(pyBuf = PyBuffer_New(len)))
 {
 return NULL;
 }

 // should use memoryview object in python3
 if (PyObject_AsWriteBuffer(pyBuf, &cbuf, &len))
 {
 Py_DECREF(pyBuf);
 return NULL ;
 }

// fill in cbuf
 ...

 return pyBuf ;

//---

I'm somewhat confounded in finding an equivalent (PyBuffer_New()) for
creating a buffer of size len that has continuous memory in the c extension
function for python3. cbuf is manipulated/filled in using c, after which
the created pyBuf is then returned. So far, I haven't found much in the way
of examples/doc for porting the deprecated Python-/C-level buffer API calls
to the new C-level buffer API/memoryview object model.

Any guidance or direction to existing doc/example is much appreciated.

If the extension isn't huge, you should consider rewriting it in Cython.
That can usually be done quite quickly - the main thing is to figure out
what the verbose C code actually does and write it down in much simpler
Python code. And it will make it easy to make the code portable and fast.
Also likely safer and more generic and versatile, because Cython covers
away a lot of the annoying boilerplate, ref-counting issues, type
conversions, etc.

For your specific problem at hand, you could use Cython's memory views:

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

They allow you to convert the input value to a 1-dim char buffer (or
whatever you need, but you mentioned the old Py2 buffer interface, which
can't do much more) by saying

 cdef char[:] my_memview = some_python_object

If you need to pass the unpacked buffer into C code, you can get the
address as "&my_memview[0]" (i.e. the address of the first item in the
buffer). Memory views themselves support fast slicing and indexing, so you
can efficiently work with them using the normal Python slicing/indexing syntax.

In case what you actually receive are not arbitrary buffers but simple byte
strings or bytearray instances, you can even use the normal byte string
coercion in Cython and simply say

 cdef char* c_string = some_python_byte_string_object

and then use that pointer to pass it on into C.

I've written a string processing tutorial for Cython here:

http://docs.cython.org/src/tutorial/strings.html

These things may take a moment to learn, especially if you are used to
doing everything in excessive manual detail in C code, but once you are
through that, you should get things done much more quickly than when trying
to do them by hand.

Stefan




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


Need help vectorizing code

2014-01-18 Thread Kevin K
I have some code that I need help vectorizing.
I want to convert the following to vector form, how can I? I want to get rid of 
the inner loop - apparently, it's possible to do so.
X is an NxD matrix. y is a 1xD vector.

def foo(X, y, mylambda, N, D, epsilon):
...
for j in xrange(D):
aj = 0
cj = 0
for i in xrange(N):
aj += 2 * (X[i,j] ** 2)
cj += 2 * (X[i,j] * (y[i] - w.transpose()*X[i].transpose() + 
w[j]*X[i,j]))

...

If I call numpy.vectorize() on the function, it throws an error at runtime.

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


Re: Need help vectorizing code

2014-01-18 Thread Joshua Landau
On 18 January 2014 20:51, Kevin K  wrote:
> def foo(X, y, mylambda, N, D, epsilon):
> ...
> for j in xrange(D):
> aj = 0
> cj = 0
> for i in xrange(N):
> aj += 2 * (X[i,j] ** 2)
> cj += 2 * (X[i,j] * (y[i] - w.transpose()*X[i].transpose() + 
> w[j]*X[i,j]))

Currently this just computes and throws away values...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Need help vectorizing code

2014-01-18 Thread Kevin K
I didn't paste the whole function, note the ... before and after. I do use the 
values.

I want to get rid of one of the loops so that the computation becomes O(D). 
Assume vectors a and c should get populated during the compute, each being 1xD.

Thanks


On Saturday, January 18, 2014 12:51:25 PM UTC-8, Kevin K wrote:
> I have some code that I need help vectorizing.
> 
> I want to convert the following to vector form, how can I? I want to get rid 
> of the inner loop - apparently, it's possible to do so.
> 
> X is an NxD matrix. y is a 1xD vector.
> 
> 
> 
> def foo(X, y, mylambda, N, D, epsilon):
> 
> ...
> 
> for j in xrange(D):
> 
> aj = 0
> 
> cj = 0
> 
> for i in xrange(N):
> 
> aj += 2 * (X[i,j] ** 2)
> 
> cj += 2 * (X[i,j] * (y[i] - w.transpose()*X[i].transpose() + 
> w[j]*X[i,j]))
> 
> 
> 
> ...
> 
> 
> 
> If I call numpy.vectorize() on the function, it throws an error at runtime.
> 
> 
> 
> Thanks

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


Re: Python declarative

2014-01-18 Thread Tim Roberts
serto...@gmail.com wrote:
>
>First, I don't like that all parenthesis, I like to differentiate 
>which type of delimiter is, this is not so bad if using spaces but 
>anyways it's a little more difficult.  Second, In regard, to using
>something like myWindow=Window rather than Window "myWindow", at 
>first I didn't liked it that much, but in the end it does tell the 
>user that the attributes can be accesed just like anything else. 

Well, this all depends on whether you want this code to BE Python code, or
just to be READ BY Python code.  That's a huge difference.  If you want
your layout to BE Python code, then you have little alternative except to
use the suggestions offered.  But if you simply want your scripts to be
interpreted by a Python program, then you can do whatever you want.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: numpy.where() and multiple comparisons

2014-01-18 Thread Tim Roberts
Peter Otten <__pete...@web.de> wrote:

>John Ladasky wrote:
>
>> On Friday, January 17, 2014 6:16:28 PM UTC-8, duncan smith wrote:
>> 
>>>  >>> a = np.arange(10)
>>>  >>> c = np.where((2 < a) & (a < 7))
>>>  >>> c
>>> (array([3, 4, 5, 6]),)
>> 
>> Nice!  Thanks!
>> 
>> Now, why does the multiple comparison fail, if you happen to know?
>
>2 < a < 7
>
>is equivalent to
>
>2 < a and a < 7
>
>Unlike `&` `and` cannot be overridden (*)

And just in case it isn't obvious to the original poster, the expression "2
< a" only works because the numpy.array class has an override for the "<"
operator.  Python natively has no idea how to compare an integer to a
numpy.array object.

Similarly, (2 < a) & (a > 7) works because numpy.array has an override for
the "&" operator.  So, that expression is compiled as

numpy.array.__and__(
numpy.array.__lt__(2, a),
numpy.array.__lt__(a, 7)
)

As Peter said, there's no way to override the "and" operator.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: question about input() and/or raw_input()

2014-01-18 Thread Terry Reedy

On 1/18/2014 1:30 PM, Roy Smith wrote:

Pardon me for being cynical, but in the entire history of the universe,
has anybody ever used input()/raw_input() for anything other than a
homework problem?


Homework problems (and 'toy' programs, such as hangman), whether in a 
programming class or elsewhere, are one of the intended use cases of 
Python. How else would you get interactive input without the complexity 
of a gui?


--
Terry Jan Reedy

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


Re: python to enable javascript , tried selinium, ghost, pyQt4 already

2014-01-18 Thread Denis McMahon
On Sun, 19 Jan 2014 05:13:57 +1100, Chris Angelico wrote:

> On Sat, Jan 18, 2014 at 10:54 PM, Jaiprakash Singh
>  wrote:
>> hi,
>>
>>  can you please suggest me some method for  study so that i can
>>  scrap a site having JavaScript behind it
>>
>>
>>  i have tried selenium, ghost, pyQt4,  but it is slow and as a am
>>  working with thread it sinks my ram memory very fast.
> 
> Do you mean "scrape"? You're trying to retrieve the displayed contents
> of a web page that uses JavaScript? If so, that's basically impossible
> without actually executing the JS code, which means largely replicating
> the web browser.

Oh, you think he meant scrape? I thought he was trying to scrap (as in 
throw away / replace) an old javascript heavy website with something 
using python instead.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Need help vectorizing code

2014-01-18 Thread Peter Otten
Kevin K wrote:

> I have some code that I need help vectorizing.
> I want to convert the following to vector form, how can I? I want to get
> rid of the inner loop - apparently, it's possible to do so. X is an NxD
> matrix. y is a 1xD vector.
> 
> def foo(X, y, mylambda, N, D, epsilon):
> ...
> for j in xrange(D):
> aj = 0
> cj = 0
> for i in xrange(N):
> aj += 2 * (X[i,j] ** 2)
> cj += 2 * (X[i,j] * (y[i] - w.transpose()*X[i].transpose()
> + w[j]*X[i,j]))
> 
> ...
> 
> If I call numpy.vectorize() on the function, it throws an error at
> runtime.

Maybe 

a = (2*X**2).sum(axis=0)
c = no idea.

Judging from the code y should be 1xN rather than 1xD. Also, should

w.transpose()*X[i].transpose()

be a vector or a scalar? If the latter, did you mean

numpy.dot(w, X[i])

?

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


Can post a code but afraid of plagiarism

2014-01-18 Thread indar kumar
Hi,

I want to show a code for review but afraid of plagiarism issues. Kindly, 
suggest how can I post it for review here without masking it visible for public
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can post a code but afraid of plagiarism

2014-01-18 Thread Roy Smith
In article ,
 indar kumar  wrote:

> Hi,
> 
> I want to show a code for review but afraid of plagiarism issues. Kindly, 
> suggest how can I post it for review here without masking it visible for 
> public

You can't.  This is a public forum.  One of the reasons people are 
willing to answer basic questions is because they knew more than one 
person will benefit from the answer.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python to enable javascript , tried selinium, ghost, pyQt4 already

2014-01-18 Thread Chris Angelico
On Sun, Jan 19, 2014 at 8:40 AM, Denis McMahon  wrote:
> On Sun, 19 Jan 2014 05:13:57 +1100, Chris Angelico wrote:
>
>> On Sat, Jan 18, 2014 at 10:54 PM, Jaiprakash Singh
>>  wrote:
>>> hi,
>>>
>>>  can you please suggest me some method for  study so that i can
>>>  scrap a site having JavaScript behind it
>>>
>>>
>>>  i have tried selenium, ghost, pyQt4,  but it is slow and as a am
>>>  working with thread it sinks my ram memory very fast.
>>
>> Do you mean "scrape"? You're trying to retrieve the displayed contents
>> of a web page that uses JavaScript? If so, that's basically impossible
>> without actually executing the JS code, which means largely replicating
>> the web browser.
>
> Oh, you think he meant scrape? I thought he was trying to scrap (as in
> throw away / replace) an old javascript heavy website with something
> using python instead.

I thought so too at first, but since we had another recent case of
someone confusing the two words, and since "scrape" would make sense
in this context, I figured it'd be worth asking the question.

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


Re: Can post a code but afraid of plagiarism

2014-01-18 Thread indar kumar
@Roy Smith

Can you help me privately because its an assignment and have to submit 
plagiarism free
-- 
https://mail.python.org/mailman/listinfo/python-list


Reference counting and the use of PYTHONDUMPREFS

2014-01-18 Thread Anders Wegge Keller
 During the final test of a bit of embedded python, I wanted to see if
I had any hanging references. To my suprise, I ended up with a rather
large amount, after running combinerefs.py. And even with the
simplest[1] possible use of embedding, I end up with 13475 still-living
references. 

 If this is the expected case, then what are the possible benefit from
running a process with the PYTHONDUMPREFS ebvironment variable set? My
code would have to be hemorrhaging in a severe way, to show up on this
background. Am I missing something here?

 The system in question is a Fedora 19 Linux, using the distribution's
Python3 debug rpm. I've seen similar results with Python 2.6, just at
a lesser scale.

1:
#include 
#include 

int main (int argc, char **argv) {

  Py_Initialize();
  Py_Finalize();

  return EXIT_SUCCESS;
}

Compiled with:

gcc pyleak.c -o pyleak `/usr/bin/python3.3dm-config --cflags`  \
  `/usr/bin/python3.3dm-config --ldflags` 


-- 
/Wegge

Leder efter redundant peering af dk.*,linux.debian.*
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can post a code but afraid of plagiarism

2014-01-18 Thread Roy Smith
In article ,
 indar kumar  wrote:

> @Roy Smith
> 
> Can you help me privately

Sorry, no.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can post a code but afraid of plagiarism

2014-01-18 Thread Chris Angelico
On Sun, Jan 19, 2014 at 9:32 AM, indar kumar  wrote:
> @Roy Smith
>
> Can you help me privately because its an assignment and have to submit 
> plagiarism free

Are you sure the requirement precludes you posting your code? More
likely, the rule is that you may not copy someone else's. When it's
posted here, it'll have your name associated with it, so anyone
checking for your code on the web will see that you posted it
yourself.

But please, before you post your code, fix your posts. You're using
the buggiest client known to this list: Google Groups. Using a
different means of posting is probably the best solution, but failing
that, you could search the web for 'Google Groups Python' and find
some useful instructions. (I'd like to see that you're able to find
things based on web search results, because that's an important
skill.)

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


Re: Can post a code but afraid of plagiarism

2014-01-18 Thread Ben Finney
indar kumar  writes:

> I want to show a code for review but afraid of plagiarism issues.

Why? What solid basis do you have to fear someone plagiarising code that
you want reviewed?

There is already a vast amount of code licensed freely for anyone to use
and derive from. What would make yours especially susceptible to
copying?

As you can tell, I strongly suspect your fears are ungrounded. You will
benefit greatly by sharing your code here and likewise benefiting from
others sharing here.

> Kindly, suggest how can I post it for review here without masking it
> visible for public

No. This forum is for the benefit of everyone who reads it, and we all
contribute on that basis.

If you want private help, you'll need to find, and provide appropriate
compensation to, someone who is willing to benefit only you.

-- 
 \“No matter how cynical you become, it's never enough to keep |
  `\up.” —Jane Wagner, via Lily Tomlin |
_o__)  |
Ben Finney

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


Re: Can post a code but afraid of plagiarism

2014-01-18 Thread Ben Finney
indar kumar  writes:

> Can you help me privately because its an assignment and have to submit
> plagiarism free

Then the point of the assignment is defeated by seeking help here.

Hopefully your instructors also read this forum and are now aware you
are seeking to subvert the anti-plagiarism rules.

-- 
 \  “It is well to remember that the entire universe, with one |
  `\   trifling exception, is composed of others.” —John Andrew Holmes |
_o__)  |
Ben Finney

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


'and' is not exactly an 'operator' (was Re: numpy.where() and multiple comparisons)

2014-01-18 Thread Terry Reedy

On 1/18/2014 3:50 AM, Peter Otten wrote:


Unlike `&` `and` cannot be overridden (*),



(*) I assume overriding would collide with short-cutting of boolean
expressions.


Yes. 'and' could be called a 'control-flow operator', but in Python it 
is not a functional operator.


A functional binary operator expression like 'a + b' abbreviates a 
function call, without using (). In this case, it could be written 
'operator.add(a,b)'. This function, or it internal equivalent, calls 
either a.__add__(b) or b.__radd__(a) or both. It is the overloading of 
the special methods that overrides the operator.


The control flow expression 'a and b' cannot abbreviate a function call 
because Python calls always evaluate all arguments first. It is 
equivalent* to the conditional (control flow) *expression* (also not a 
function operator) 'a if not a else b'. Evaluation of either expression 
calls bool(a) and hence a.__bool__ or a.__len__.


'a or b' is equivalent* to 'a if a else b'

* 'a (and/or) b' evaluates 'a' once, whereas 'a if (not/)a else b' 
evaluates 'a' twice. This is not equivalent when there are side-effects. 
Here is an example where this matters.

 input('enter a non-0 number :') or 1

--
Terry Jan Reedy

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


Re: How to write this as a list comprehension?

2014-01-18 Thread John Allsup

Hi,

I'd agree with the advice that it's not the best idea: readability sucks 
here, but consider the following:



import time

def somefunc(a,b,c,d): # dummy function
return "{} - {} - {} : {}".format(a,b,c,d)
l = [(time.time(),"name {}".format(n)) for n in range(100)] # dummy data

# the line in question
labels = [somefunc(*(lambda t,n: 
(t.tm_mon,t.tm_mday,t.tm_wday,n))(time.localtime(x[0]),x[1])) for x in l]



print(labels) # just to see the result


If you find that hard to decipher, the consider the maintainability of 
code you write that uses such comprehensions.  You need to include 
comments that explain what this does, and it is easier to write a 
longhand version using .append() and variable assignments.  I presume
performance won't be an issue determining the right approach, since then 
you'd be using C or C++.


John

On 17/01/2014 23:49, Dan Stromberg wrote:

On Fri, Jan 17, 2014 at 3:19 PM, Piet van Oostrum  wrote:

Hi,

I am looking for an elegant way to write the following code as a list
comprehension:

labels = []
for then, name in mylist:
 _, mn, dy, _, _, _, wd, _, _ = localtime(then)
 labels.append(somefunc(mn, day, wd, name))


My recomendation: Don't use a list comprehension.  List comprehensions
and generator expressions are great for quick little things, but
become less readable when you have to string them over multiple
physical lines.


labels = [somefunc(mn, day, wd, name)
 for then, name in mylist
 for _, mn, dy, _, _, _, wd, _, _ in [localtime(then)]]


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


Help with simple code that has database defined

2014-01-18 Thread indar kumar
I have to save students information in a database that is keeping continuously 
track of the information. Format is as follows:
Information:

Note: if this name already exists there in database, just update the 
information of that(name) e.g course,grade and date. Otherwise, add it.

What I think:

Database={}   #First Created a dictionary that will keep track
z = "Enter student name, course, grade and duration: "
line = raw_input(z)   
while (line != "quit"):
data = line.split()
name = data[0]
line = raw_input(z)   

This is just part because this is what I know how to do, for rest have no idea

The output should be like this:
{'alex': ['7', '8', '6'], 'john': ['9', '8', '7']})

Now as program will continuously prompt for input. If user enters “quit” it 
would exit. Otherwise it keeps taking input.

Now if there is already a name existing for example “alex” and his course, 
grade and duration are 7,8,6. Now in next turn of input if user again enters 
the name as alex but different entries for him e.g 9,9,9 so it should replace 
the older info by new e.g. it should replace 7,8,6 for alex by 9,9,9 and if 
user enters a entirely new name that is not in dictionary then it should be 
added to dictionary for example nancy 6 6 6 is the input then output should be:

{'alex': ['7', '8', '6'], 'john': ['9', '8', '7'],’nancy’:[‘6’,’6’,’6’]})


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


Re: question about input() and/or raw_input()

2014-01-18 Thread Chris Angelico
On Sun, Jan 19, 2014 at 8:33 AM, Terry Reedy  wrote:
> On 1/18/2014 1:30 PM, Roy Smith wrote:
>>
>> Pardon me for being cynical, but in the entire history of the universe,
>> has anybody ever used input()/raw_input() for anything other than a
>> homework problem?
>
>
> Homework problems (and 'toy' programs, such as hangman), whether in a
> programming class or elsewhere, are one of the intended use cases of Python.
> How else would you get interactive input without the complexity of a gui?

With the network :) I've written plenty of programs whose sole
interaction is via sockets (telnet, HTTP, SMTP, whatever), or a
database, or somesuch.

But I've also written my share of interactive programs that use the
console. Plenty of programs don't need the fanciness of a GUI, but
need to prompt the user for stuff. If I write something for my brother
(and only him), I'm inclined to spend less effort on the UI than I
would for something of wide distribution, and console I/O is
approximately zero effort.

BTW, I'm assuming your mention of "input()/raw_input()" is covering
Py3 and Py2, respectively. I have *never* used input() in live Py2
code, and never intend to. It's way too subtle. On those really rare
occasions when you actually want to take something from the user and
immediately eval it, the extra keystrokes for eval(raw_input()) are,
IMO, a small price for the clarity.

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


Re: question about input() and/or raw_input()

2014-01-18 Thread Rustom Mody
On Sunday, January 19, 2014 12:00:20 AM UTC+5:30, Roy Smith wrote:
> Pardon me for being cynical, but in the entire history of the universe, 
> has anybody ever used input()/raw_input() for anything other than a 
> homework problem?

Similar 'cynicism' regarding print would be salutary for producing better 
programmers

[If youve taught programming and had to deal with code strewn with prints...]

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


Re: question about input() and/or raw_input()

2014-01-18 Thread Chris Angelico
On Sun, Jan 19, 2014 at 3:15 PM, Rustom Mody  wrote:
> On Sunday, January 19, 2014 12:00:20 AM UTC+5:30, Roy Smith wrote:
>> Pardon me for being cynical, but in the entire history of the universe,
>> has anybody ever used input()/raw_input() for anything other than a
>> homework problem?
>
> Similar 'cynicism' regarding print would be salutary for producing better 
> programmers
>
> [If youve taught programming and had to deal with code strewn with prints...]

Why, exactly? How ought a program to produce filterable output?

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


Re: question about input() and/or raw_input()

2014-01-18 Thread Rustom Mody
On Sunday, January 19, 2014 9:51:36 AM UTC+5:30, Chris Angelico wrote:
> On Sun, Jan 19, 2014 at 3:15 PM, Rustom Mody  wrote:
> > On Sunday, January 19, 2014 12:00:20 AM UTC+5:30, Roy Smith wrote:
> >> Pardon me for being cynical, but in the entire history of the universe,
> >> has anybody ever used input()/raw_input() for anything other than a
> >> homework problem?
> > Similar 'cynicism' regarding print would be salutary for producing better 
> > programmers
> > [If youve taught programming and had to deal with code strewn with 
> > prints...]

> Why, exactly? How ought a program to produce filterable output?

Because these two pieces of code

>>> def foo(x): print x+1

>>> def bar(x): return x+1

look identical (to a beginner at least)

>>> foo(3)
4
>>> bar(3)
4
>>> 

And so if they see prints used cavalierly for demo purposes, they think the
prints are also ok for production.

As a professional programmer, you would of course understand
- 'normal' code that does some processing and then some output should not 
have prints in the processing
- web-serving (type of) code that has little other than heavy-duty printing
should probably use a template engine of some sort

In any case prints all over is a code-smell
exacerbated by the way that manuals/examples need to be written
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: question about input() and/or raw_input()

2014-01-18 Thread Chris Angelico
On Sun, Jan 19, 2014 at 3:43 PM, Rustom Mody  wrote:
> Because these two pieces of code
>
 def foo(x): print x+1
>
 def bar(x): return x+1
>
> look identical (to a beginner at least)
>
 foo(3)
> 4
 bar(3)
> 4


As do these pieces of code:

>>> def quux(x): return str(x+1)
>>> def quux(x): return hex(x+1)[2:]

But we don't decry hex or str because of it. Every function has its
use and purpose. If someone uses the wrong tool for the job, s/he will
have to figure that out at some point - it doesn't mean the tool is
wrong.

If you're not using the REPL, print is critical. Don't assume everyone
uses interactive mode.

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


graphical python

2014-01-18 Thread buck
I'm trying to work through Skienna's algorithms handbook, and note that the 
author often uses graphical representations of the diagrams to help understand 
(and even debug) the algorithms. I'd like to reproduce this in python.

How would you go about this? pyQt, pygame and pyglet immediately come to mind, 
but if I go that route the number of people that I can share my work with 
becomes quite limited, as compared to the portability of javascript projects.

I guess my question really is: has anyone had success creating an interactive 
graphical project in the browser using python?

Is this a dream I should give up on, and just do this project in 
coffeescript/d3?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: question about input() and/or raw_input()

2014-01-18 Thread Steven D'Aprano
On Sat, 18 Jan 2014 13:30:20 -0500, Roy Smith wrote:

> Pardon me for being cynical, but in the entire history of the universe,
> has anybody ever used input()/raw_input() for anything other than a
> homework problem?

Yes. They are excellent for interactive command line tools.


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


Re: Can post a code but afraid of plagiarism

2014-01-18 Thread Steven D'Aprano
On Sat, 18 Jan 2014 14:32:21 -0800, indar kumar wrote:

> @Roy Smith
> 
> Can you help me privately because its an assignment and have to submit
> plagiarism free

Then don't plagiarise.


Plagiarism means YOU copy other people. You shouldn't get in trouble 
because other people copy you.

Talk to your tutor or teacher and ask what the school's policy is about 
asking for external help on projects. Some schools will allow it if you 
explain what help you received. Some prohibit it all together.

In general, we will help with questions about Python syntax and 
libraries, but we try not to write your code for you. If you make a good-
faith attempt to solve the problem, and then ask for help, we shall try 
to assist. But as I said, you should find out what your school or 
university's policy is.


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


Re: Can post a code but afraid of plagiarism

2014-01-18 Thread Devin Jeanpierre
On Sat, Jan 18, 2014 at 10:31 PM, Steven D'Aprano
 wrote:
> Plagiarism means YOU copy other people. You shouldn't get in trouble
> because other people copy you.

Normally, both the person copying and the person who gave away their
work to be copied are punished. It simplifies figuring out who to
punish, and discourages people from enabling cheaters.

If one of their fellow students copied their assignment, they actually
likely would be in trouble, and could be expelled or failed.

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


Re: Beginner Tutorials

2014-01-18 Thread simsonsjanis
On Friday, 18 January 2013 16:47:52 UTC+2, Rik  wrote:
> Hi, I've developed a website for beginners to Python. I'd appreciate any 
> comments or criticism. It's still under development, and should be finished 
> in the next few months. Oh, and it's free to use.
> 
> 
> 
> www.usingpython.com

code solutions should be collapsed by default, imho
-- 
https://mail.python.org/mailman/listinfo/python-list