Re: [Tutor] env var packages

2013-05-15 Thread vasya
2013/5/15 vasya 

> Hi, Matthew
>
> First of all, please state what OS do you using?
> I think its ubuntu because some kind of this problem I've alredy solved
> some time ago: when I've need something like to add "djando-admin.py"  to
> my PATH.
>
> What you need to do is to delete your django install that you make from
> easy_install and install django from package-manager that provide your
> system. How to delete is described here:
> https://docs.djangoproject.com/en/dev/topics/install/#remove-any-old-versions-of-django
>
> And how to install django depends from system to system... As I said
> specify it. For ubuntu it is "apt-get install python-django". BTW
> installing packages from packet-manager the most common and the most
> clearly and best way to install. Do not try to clone it from git or tar.gz
> source code unless you what you do. Or try to use checkinstall (in ubuntu).
>
> About what "djando-admin.py" do. This is script file that generates simple
> structure of your future code, small enviroment like "hello world" in other
> programming languages. In some distributions (like ubuntu AFAIK) its also
> can start simple HTTP server for debugging your django project. On
> different systems there is also exists "manage.py" module which also do
> this (and this is common way that describes in books). Also it provides
> some interface to manipulate on different settings of your django project.
> To make simple "hello world" enviroment you should write in your terminal
> something like: "django-admin startproject helloworld"
>
>
> 2013/5/14 Matthew Ngaha 
>
>> i have to install django and ive come across some weird instructions.
>> it says to set Django's  django-admin.py file to my environment
>> variable. I was instructed to get django via easy installer that was
>> located in my Python/Scripts folder. it installed django to a
>> different place in site-packages, where django-admin.py resides.But
>> now its telling me to add this file to my env variable and it should
>> also be located in Python/Scripts .. but as i've said, its clearly not
>> there, it is somewhere in a site-packages/django sub folder. so is
>> this an error? or do i go ahead and add Python/Scripts to the env
>> variable, even those the file points somewhere else?
>>
>> My 2nd problem is it says after adding it i will get a python
>> interpreter and Django's djando-admin.py commad up and running. What
>> does this mean? both files open? it was specific about adding the path
>> to the env variable, but if i already have python added, why do i need
>> to add django? shouldnt it already be added? i will quote:
>>
>> "You should make sure "djando-admin.py" is in your PATH environment
>> variable so that it can be executed from the command-line (unless you
>> like calling interpreters by using full pathnames)"
>>
>> does this mean in a terminal, that i can be in
>> "Python/myproject/script_one/" and be able to open a .py file in
>> "Python/myproject/script_two/" by simpling typing its file name
>> without having to cd into its directory or typing its full path?
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
> Sorry for top-post. Google mail make it by default... :-(
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] env var packages

2013-05-15 Thread vasya
Hi, Matthew

First of all, please state what OS do you using?
I think its ubuntu because some kind of this problem I've alredy solved
some time ago: when I've need something like to add "djando-admin.py"  to
my PATH.

What you need to do is to delete your django install that you make from
easy_install and install django from package-manager that provide your
system. How to delete is described here:
https://docs.djangoproject.com/en/dev/topics/install/#remove-any-old-versions-of-django

And how to install django depends from system to system... As I said
specify it. For ubuntu it is "apt-get install python-django". BTW
installing packages from packet-manager the most common and the most
clearly and best way to install. Do not try to clone it from git or tar.gz
source code unless you what you do. Or try to use checkinstall (in ubuntu).

About what "djando-admin.py" do. This is script file that generates simple
structure of your future code, small enviroment like "hello world" in other
programming languages. In some distributions (like ubuntu AFAIK) its also
can start simple HTTP server for debugging your django project. On
different systems there is also exists "manage.py" module which also do
this (and this is common way that describes in books). Also it provides
some interface to manipulate on different settings of your django project.
To make simple "hello world" enviroment you should write in your terminal
something like: "django-admin startproject helloworld"


2013/5/14 Matthew Ngaha 

> i have to install django and ive come across some weird instructions.
> it says to set Django's  django-admin.py file to my environment
> variable. I was instructed to get django via easy installer that was
> located in my Python/Scripts folder. it installed django to a
> different place in site-packages, where django-admin.py resides.But
> now its telling me to add this file to my env variable and it should
> also be located in Python/Scripts .. but as i've said, its clearly not
> there, it is somewhere in a site-packages/django sub folder. so is
> this an error? or do i go ahead and add Python/Scripts to the env
> variable, even those the file points somewhere else?
>
> My 2nd problem is it says after adding it i will get a python
> interpreter and Django's djando-admin.py commad up and running. What
> does this mean? both files open? it was specific about adding the path
> to the env variable, but if i already have python added, why do i need
> to add django? shouldnt it already be added? i will quote:
>
> "You should make sure "djando-admin.py" is in your PATH environment
> variable so that it can be executed from the command-line (unless you
> like calling interpreters by using full pathnames)"
>
> does this mean in a terminal, that i can be in
> "Python/myproject/script_one/" and be able to open a .py file in
> "Python/myproject/script_two/" by simpling typing its file name
> without having to cd into its directory or typing its full path?
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Oscar Benjamin
On 14 May 2013 17:11, Marc Tompkins  wrote:
>
> The OP expressed some confusion between what a function DOES and what it 
> RETURNS.  It occurs to me that the print() function (or, more generically, 
> ANY print() function - it doesn't have to be Python 3) is a good 
> demonstration.
>
> Our first exposure to print() is very simple: display something on the screen 
> - what could possibly go wrong?  However, print() can redirect its output to 
> files, printers, skywriters, etc. - and sometimes it will be a real question 
> whether print() succeeded in producing any output.  (If your program is 
> trying to write data into a file, you'd probably like to know whether it 
> worked or not.)  So print() - like all functions - has an optional return 
> value, which your program can read to see whether it needs to retry, display 
> an error message, etc.
>
> Again, the return value of print() - e.g. success/failure - is separate from 
> what print() actually prints.


I was surprised by this so I've just tested it and checked the docs;
the print() function does not return anything (i.e. it returns None).

>>> a = print('qwe')
qwe
>>> a
>>> print(a)
None

http://docs.python.org/3/library/functions.html#print


Oscar
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Steven D'Aprano
On Wed, May 15, 2013 at 10:03:20AM +0100, Oscar Benjamin wrote:
> On 14 May 2013 17:11, Marc Tompkins  wrote:

> > Again, the return value of print() - e.g. success/failure - is 
> > separate from what print() actually prints.
> 
> 
> I was surprised by this so I've just tested it and checked the docs;
> the print() function does not return anything (i.e. it returns None).

I assumed Marc was talking hypothetically. A print function *could* 
return a result, even if Python's print function does not.


-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] env var packages

2013-05-15 Thread eryksun
On Tue, May 14, 2013 at 3:54 PM, Matthew Ngaha  wrote:
> I was instructed to get django via easy installer that was
> located in my Python/Scripts folder. it installed django to a
> different place in site-packages, where django-admin.py resides.

You appear to be using Windows, since you talk about a "Scripts"
directory (other platforms use a "bin" directory such as "/usr/bin").

easy_install *should* have created django-admin.py in the Scripts
directory. It worked for me on a fresh install of a 3.3.1, installing
Django 1.5.1. Maybe the problem is minor, and you can just copy
django-admin.py to the Scripts directory manually. If possible I'd
start over fresh. Also, I'd use pip instead of easy_install. It's
easier to uninstall with pip. If you decide to start fresh, first
install Python, distribute, and pip; then add the Scripts directory to
PATH; then run "pip install django".

Here are the scripts for installing distribute and pip:

http://python-distribute.org/distribute_setup.py
https://raw.github.com/pypa/pip/master/contrib/get-pip.py

Use a "command prompt" with elevated privileges (i.e. "Run as Administrator").

> it was specific about adding the path to the env variable, but if i already
> have python added, why do i need to add django? shouldnt it already
> be added?

When you open (execute) a file without a full or relative path, the
shell searches for the file in the directories listed in the PATH
environment variable. Additionally, if you don't specify an extension,
the cmd shell searches for the filename plus each extension listed in
PATHEXT (e.g. .EXE, .BAT). The first match becomes the fully qualified
path. Given a valid path, the shell executes the "open" command
associated with the file's extension, which is found in the system
registry under HKCR (classes root).

Specifically, when you add the Scripts directory to PATH, it allows
you to execute the files in that directory as commands, irrespective
of your current working directory. Additionally if you add .PY to the
PATHEXT environment variable, you can skip using the .py extension.
For example, you would simply run "django-admin".

One limitation with this scheme is that the file type can only be
configured for a particular executable at a time. It doesn't take into
account, for example, having multiple Python interpreters installed on
the same machine, all of which contend for the same .py extension. The
new launcher for Windows (py.exe) gets around this problem by acting
as a dispatcher based on the first line of the script (the "shebang").
The launcher is installed with 3.3 and available as a separate
download for previous versions:

https://bitbucket.org/pypa/pylauncher
https://bitbucket.org/pypa/pylauncher/raw/tip/Doc/launcher.rst
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] env var packages

2013-05-15 Thread Matthew Ngaha
Thank you Vasya and Eryksun. Sorry i didn't mention my OS i am on
windows. Thanks for the links and detailed explanations which after
following, i now have django up and running! thanks again
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Marc Tompkins
On Wed, May 15, 2013 at 2:26 AM, Steven D'Aprano wrote:

I assumed Marc was talking hypothetically. A print function *could*
> return a result, even if Python's print function does not.
>
> Actually, I was mixing up my memory of an overloaded print() function with
Python's built-in print().  I _have_ used versions of print() that returned
values, and relied on them for program flow - but somehow I forgot that
that was a custom function!

Yet another argument in the ongoing controversy "why change print from a
statement to a function?"
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Alan Gauld

On 15/05/13 16:51, Marc Tompkins wrote:


Actually, I was mixing up my memory of an overloaded print() function


And C's printf() returns the number of chars printed.
I actually wish python had followed suit because, as Marc says,
it can occasionally be useful...

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Marc Tompkins
On Wed, May 15, 2013 at 1:02 PM, Alan Gauld wrote:

> On 15/05/13 16:51, Marc Tompkins wrote:
>
>  Actually, I was mixing up my memory of an overloaded print() function
>>
>
> And C's printf() returns the number of chars printed.
> I actually wish python had followed suit because, as Marc says,
> it can occasionally be useful...
>
>
I wonder if this would be a good PEP suggestion?  Unlike the switch from
print to print(), I think this could be done in a future-proof way...
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Oscar Benjamin
On 15 May 2013 22:21, Marc Tompkins  wrote:
> On Wed, May 15, 2013 at 1:02 PM, Alan Gauld 
> wrote:
>>
>> And C's printf() returns the number of chars printed.
>> I actually wish python had followed suit because, as Marc says,
>> it can occasionally be useful...
>>
>
> I wonder if this would be a good PEP suggestion?  Unlike the switch from
> print to print(), I think this could be done in a future-proof way...
>

It would be a bit confusing in an interactive session:

>>> def print_(data):
... print(data)
... return len(data)
...
>>> print_('asd')
asd
3


Oscar
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Marc Tompkins
On Wed, May 15, 2013 at 3:43 PM, Oscar Benjamin
wrote:

> On 15 May 2013 22:21, Marc Tompkins  wrote:
> > On Wed, May 15, 2013 at 1:02 PM, Alan Gauld 
> > wrote:
> >>
> >> And C's printf() returns the number of chars printed.
> >> I actually wish python had followed suit because, as Marc says,
> >> it can occasionally be useful...
> >>
> >
> > I wonder if this would be a good PEP suggestion?  Unlike the switch from
> > print to print(), I think this could be done in a future-proof way...
> >
>
> It would be a bit confusing in an interactive session:
>
> >>> def print_(data):
> ... print(data)
> ... return len(data)
> ...
> >>> print_('asd')
> asd
> 3
>
>
I was thinking along the lines of an optional parameter ("verbose" or
something similar), so print() would supply a return value if you asked it
to but keep stumm if you didn't.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Oscar Benjamin
On 15 May 2013 23:52, Marc Tompkins  wrote:
> On Wed, May 15, 2013 at 3:43 PM, Oscar Benjamin 
> wrote:
>>
>> On 15 May 2013 22:21, Marc Tompkins  wrote:
>> > On Wed, May 15, 2013 at 1:02 PM, Alan Gauld 
>> > wrote:
>> >>
>> >> And C's printf() returns the number of chars printed.
>> >> I actually wish python had followed suit because, as Marc says,
>> >> it can occasionally be useful...
>> >>
>> >
>> > I wonder if this would be a good PEP suggestion?  Unlike the switch from
>> > print to print(), I think this could be done in a future-proof way...
>> >
>>
>> It would be a bit confusing in an interactive session:
>>
>> >>> def print_(data):
>> ... print(data)
>> ... return len(data)
>> ...
>> >>> print_('asd')
>> asd
>> 3
>>
>
> I was thinking along the lines of an optional parameter ("verbose" or
> something similar), so print() would supply a return value if you asked it
> to but keep stumm if you didn't.

I don't really understand what the reason for having the information
is. Would it return the number of characters written or the number of
bytes?


Oscar
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Marc Tompkins
On Wed, May 15, 2013 at 3:52 PM, Marc Tompkins wrote:


> I was thinking along the lines of an optional parameter ("verbose" or
> something similar), so print() would supply a return value if you asked it
> to but keep stumm if you didn't.
>

After I hit Send, I thought of the obvious problem...  you'd have to know
ahead of time which version of print() was available, because you'll get a
TypeError if you pass undefined keyword arguments to print().

On the other hand, it'd be a quickie to do that test at the top of your
code...
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Marc Tompkins
On Wed, May 15, 2013 at 4:14 PM, Oscar Benjamin
wrote:

> I don't really understand what the reason for having the information
> is. Would it return the number of characters written or the number of
> bytes?
>

It's absolutely useless in an interactive session, or any time that print()
is printing to the screen and the user can see it happening.  But when
you're printing to some other device - a disk file, a printer, a serial
port - it can be EXTREMELY handy to know 1) did it succeed or not and 2) if
it failed, how far did it get before it failed?

As for characters or bytes, that would depend on whether you were working
in ASCII or Unicode, I suppose...
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Alan Gauld

On 16/05/13 00:18, Marc Tompkins wrote:

On Wed, May 15, 2013 at 3:52 PM, Marc Tompkins mailto:marc.tompk...@gmail.com>> wrote:

I was thinking along the lines of an optional parameter ("verbose"
or something similar), so print() would supply a return value if you
asked it to but keep stumm if you didn't.


After I hit Send, I thought of the obvious problem...  you'd have to
know ahead of time which version of print() was available, because
you'll get a TypeError if you pass undefined keyword arguments to print().

On the other hand, it'd be a quickie to do that test at the top of your
code...


Or maybe we need a printf function in Python that has the C behaviour 
(and takes other arguments, such as output stream?)


As to bytes v characters I'd opt for bytes since in dealing with 
hardware/networks the bytes are more significant than the

characters...


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Programming for the Absolute Beginner

2013-05-15 Thread Grace Kathryn
Hello~

I'm working through the Book Python Programming for the Absolute Beginner and 
am wondering if you could help me out with the coding to certain
Challenges at the end of the book, specifically chapter 7 challenges 1 and 2 
and chapter 8 challenges 1 and 3.
Could you help? I need something to compare my coding to.

Thank you!

~Grace
Sent from my iPad___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] changing char list to int list isn't working

2013-05-15 Thread Bhanu Pratap Singh
Hi Jim,
When you replace num = int(num); it's not changing a list.
Due to It only pick a value from a list.
You have to pointing to list so,
You have to use list[position] using while loop like below

listOfNumChars = list(str(intNum))
i = 0
while i < len(listOfNumChars):
listOfNumChars[i] = int(listOfNumChars[i])
i += 1

print(listOfNumChars)

#--> [4, 5, 5] (if you entered 455)


Best,
Bhanu Pratap


-Original Message-
From: Tutor [mailto:tutor-bounces+bhanubais=gmail@python.org] On Behalf Of 
Jim Mooney
Sent: Saturday, May 04, 2013 9:43 AM
To: tutor@python.org
Subject: [Tutor] changing char list to int list isn't working

I'm turning an integer into a string so I can make a list of separate chars, 
then turn those chars back into individual ints, but the resulting list still 
looks like string chars when I print it. What am I doing wrong?


listOfNumChars = list(str(intNum))
for num in listOfNumChars:
num = int(num)

print(listOfNumChars)

# result of 455 entered is ['4', '5', '5']

--
Jim Mooney

“For anything that matters, the timing is never quite right, the resources are 
always a little short, and the people who affect the outcome are always 
ambivalent.”
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Looking for python 3 tutorial

2013-05-15 Thread Sky Flyinz
Where can I find a  web programming python tutorial online either book?

 Are social media, email, live talk, and etc that called web programming
for browser?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] POST MULTI PART DATA WITH PYTHON

2013-05-15 Thread Japhy Bartlett
In your code, you're not actually inserting the contents of the file into
your MIME part (you're only constructing headers), which is why the
content-length is not right.

The 404 is probably the site detecting this as a script/robot/violation of
their TOS and blocking you.  Which you can probably get around by modifying
your user-agent string, but as a security guy I suppose you can figure that
out.

If you understand that there are better libraries but refuse to use them,
you might try at least looking at how they implement this.


On Mon, May 6, 2013 at 12:05 PM, Ajin Abraham  wrote:

> Hi,
>I was working on a python project that requires to upload an image
> using httplib. Here i need to POST a MULTI PART DATA with Python using
> inbuilt libraries. I know there are better libraries like requests and
> poster. but i need to do it with httplib itself.
>
> I will attach a screenshot==> http://s1.postimg.org/qjjhy445q/file.jpg
>
> So here i think there is some problem with my code that the
> 'Content-Length is different and i am getting a 404 not found
> response. i placed the file "screenshot.png" together with my python
> source file.
>
> Here is my source code==>http://bpaste.net/show/V2xbtcBSpYsNbwGPCmFM/
>
> Please tell me what's wrong in my code. and please don't suggest me
> other libraries.
>
> Regards,
> Ajin Abraham
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] question already discussed with oscar benjamin

2013-05-15 Thread Linsey Raaijmakers
Hi,

Im trying to work with the help Oscar provided me, but I still get stuck :(
So what I'm trying to do now is write the program with the following input
and output:

Input:
action,start,apex,stop
3, 12, 13, 15
4, 15, 15, 15
3, 20, 21, 25
5, 21, 23, 30
...

And when you run your program it prints out:
actions, start, stop
[3], 12, 13
[], 14,15
[4], 15, 15
[], 16, 19
[3], 20, 21
[3, 5], 21, 21
[5], 22, 23
...

I don't want to use the stop. Only the start till apex is important.

This is the code I have now:

now = onset_list[0]
end = apex_list[0]
active = action_list[0]

for i in range(1,len(onset_list)):
  next_start = onset_list[i]
  next_end = apex_list[i]
  next_active = action_list[i]
  prev_end = apex_list[i-1]

  while next_start > end:
print active+"\t"+now+'\t'+end
end = next_end
now = next_start
active = next_active
  print active+','+next_active+'\t'+now+'\t'+next_end

But my output will print now:

31213
4,4  1515
4 1515
3,3   2021
3,5   2025

How do I fix that it doesn't print out the double ones?
I'm sorry that I can't figure it out without your help. Im really trying..
:(
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python beginner-doubt

2013-05-15 Thread subha krishna
hi,

  i need an help in the following program

i just started to learn.

if speed >= 80:
print 'License and registration please'
if mood == 'terrible' or speed >= 100:
print 'You have the right to remain silent.'
elif mood == 'bad' or speed >= 90:
print "I'm going to have to write you a ticket."
write_ticket()
else:
print "Let's try to keep it under 80 ok?"

in this prgm how to give  the value of speed  and mood.

i have written like this to get the value

def main():
print 'enter the speed and mood'
print 'enter the speed',speed
if speed >= 80:
print 'License and registration please'
print 'enter the mood',mood
if mood== 'terrible' or speed >=100
print 'you hve the right to remain silent.'
elif mood =='bad' or speed >=90:
print "I 'm going to have to write you a ticket."
write_ticket()
else:
print "Let's try to keep it under 80 ok?"

i am getting  error in this line (if mood== 'terrible' or speed >=100)

kindly give me an idea about the mistake and how to get the values...


thanks and regards
subha
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help needed!!

2013-05-15 Thread Linsey Raaijmakers
Hello,

I have a file with actions and time points at which they occur.
I want to find how many times an action occurs, and how many times it
occurs in combination with an other action at the same time point
(overlapping between onset and apex)

Below is the input file. in this file, action 50 occurs 3 times, so I want
to output that with the apex of those occurrences. It also occurs in
combination with action 45, so I also want to output that combination plus
the number of times it occurs.
In this case 50 overlaps 45 and 45 also overlaps 50, but I only want to
output this combination once. So not [50,45] and [45,50]

I'm working on it for some days now, but I can't figure out how to do this.
I first wanted to make a list of the first action and just add the next
action to that list if it is overlapping the first one. And keep doing that
until the next action isn't overlapping anymore and create a new list, but
I'm doing something wrong what makes it not doing what I want.

Can somebody please help me? :)

INPUT:
  Action Unit Onset Frame Apex Frame Offset Frame  50 5321 5321 5424  7 5323
5347 5441  12 5339 5351 5449  45 5373 5373 5373  45 5420 5420 5420  25 5425
5425 5450  26 5425 5425 5450  50 5451 5451 5498  45 5452 5452 5452  14 5497
5503 5509  26 5513 5513 5532  25 5517 5517 5532  45 5533 5533 5533  50 5533
5533 5580  5 5537 5540 5583  25 5580 5580 5633  45 5586 5586 5586  26 5595
5595 5633
OUTPUT:

action times observedapex
[50]3 5321, 5451, 5533
[50,45]   1  5533;5533
[7]  1 5347
[7,12]  1 5347; 5351
..


Multiple combinations of actions are possible, as long as they overlap
between onset and apex.




CODE:

from collections import Counter
f = open('and.txt','r');

action_list = []
onset_list = []
apex_list = []
offset_list = []
action_counter = 0
combination_list = []

for line in f:
  action, onset, apex, offset = line.split()

  action_list.append(action)
  onset_list.append(onset)
  apex_list.append(apex)
  offset_list.append(offset)

action_cnvrt = map(int, action_list)
c = Counter(action_cnvrt)

filtered = list(set(action_list))
filtered_cnvrt = map(int, filtered)

for a in filtered_cnvrt:
  action_count = str(a)+"\t"+str(c[a])

now = int(onset_list[0])
end = int(apex_list[0])
active = action_list[0]

for i in range(1,len(onset_list)):
  next_start = int(onset_list[i])
  next_end = int(apex_list[i])
  next_active = action_list[i]
  prev_end = int(apex_list[i-1])
  combination_list.append(action_list[i-1])

  print combination_list
  while next_start <= end:
combination_list.append(action_list[i])
end = next_end
  combination_list = []
  end = next_end
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2013-05-15 Thread Krish Nagpal
Good Afternoon,
I have a quick question based on python 2.7. Do you know how to write a web
server with a form. (Pthyon) When the webserver gets a GET request, I need
to serve the HTML document with a form. In response to a POST, i want to
write the resulting data to a form.

Do you know how to do this. Can you please help me quickly. Thanks a lot.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Interested in learning Python

2013-05-15 Thread Raymond Jackson
Hello My name is Raymond Jackson I am currently on your tutorial site and
trying to teach my self this new language I haven't done this before
so i'm open to any suggestions going about this
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Programming for the Absolute Beginner

2013-05-15 Thread Amit Saha
Hi Grace,


On Thu, May 2, 2013 at 8:04 AM, Grace Kathryn
wrote:

> Hello~
>
> I'm working through the Book Python Programming for the Absolute Beginner
> and am wondering if you could help me out with the coding to certain
> Challenges at the end of the book, specifically chapter 7 challenges 1 and
> 2 and chapter 8 challenges 1 and 3.
> Could you help? I need something to compare my coding to.
>

Welcome. I am sure somebody will be able to help you out. However,  you
would need to tell what exactly the challenges are and if possible, any
specific problem you are facing for someone to help you. Not all of the
members in this list may have access to the book.

Best,
Amit.


>
> Thank you!
>
> ~Grace
> Sent from my iPad
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
http://echorand.me
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Programming for the Absolute Beginner

2013-05-15 Thread Robert Sjoblom
> I'm working through the Book Python Programming for the Absolute Beginner and 
> am wondering if you could help me out with the coding to certain
> Challenges at the end of the book, specifically chapter 7 challenges 1 and 2 
> and chapter 8 challenges 1 and 3.
Since I personally don't have that particular book, and I imagine many
others on this mailing list don't either, it'll be hard for us to
comment on the challenges, given that we don't know what they are.
--
best regards,
Robert S.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Steven D'Aprano

On 16/05/13 06:02, Alan Gauld wrote:

On 15/05/13 16:51, Marc Tompkins wrote:


Actually, I was mixing up my memory of an overloaded print() function


And C's printf() returns the number of chars printed.
I actually wish python had followed suit because, as Marc says,
it can occasionally be useful...



Guido's time machine strikes again.


py> import sys
py> sys.stdout.write('NOBODY expects the Spanish Inquisition!\n')
NOBODY expects the Spanish Inquisition!
40


The write() method of file objects in Python 3 return the number of characters 
written.



--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python beginner-doubt

2013-05-15 Thread Dave Angel
Somehow, your message didn't appear here for 9 days.  That's probably 
why you haven't seen any responses yet.


On 05/06/2013 01:26 AM, subha krishna wrote:

hi,

   i need an help in the following program

i just started to learn.

if speed >= 80:
print 'License and registration please'


Indentation is lost here and elsewhere in the program.  That's probably 
because your email program is mistakenly set to send html messages. 
Please use text mail on this forum.  Losing indentation is just one of 
the problems triggered by html, but it's very important in python.



if mood == 'terrible' or speed >= 100:
print 'You have the right to remain silent.'
elif mood == 'bad' or speed >= 90:
print "I'm going to have to write you a ticket."
write_ticket()
else:
print "Let's try to keep it under 80 ok?"

in this prgm how to give  the value of speed  and mood.

i have written like this to get the value

def main():
 print 'enter the speed and mood'
 print 'enter the speed',speed
 if speed >= 80:
 print 'License and registration please'
 print 'enter the mood',mood
 if mood== 'terrible' or speed >=100
 print 'you hve the right to remain silent.'
 elif mood =='bad' or speed >=90:
 print "I 'm going to have to write you a ticket."
 write_ticket()
 else:
 print "Let's try to keep it under 80 ok?"

i am getting  error in this line (if mood== 'terrible' or speed >=100)


When you show an error, you should give the complete traceback.  in this 
case, it didn't matter, however.


An if statement must end with a colon.



kindly give me an idea about the mistake and how to get the values...



You would use the raw_input() statement.  print() doesn't wait for any 
keystrokes from the user, it just displays things.


Note that the return value of raw_input() is a string, so in the case of 
speed, you'll need to convert it to an int or float.



--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Interested in learning Python

2013-05-15 Thread Dave Angel

(Your message suddenly appeared here today, after four days in limbo)


On 05/11/2013 08:50 AM, Raymond Jackson wrote:

Hello My name is Raymond Jackson I am currently on your tutorial site


Be explicit.  There are lots of tutorial sites around.  Perhaps you mean 
 http://docs.python.org/tutorial/

or http://www.alan-g.me.uk/



and trying to teach my self this new language I haven't done this before
so i'm open to any suggestions going about this



Many people are new to Python, but have programmed in one or ten other 
languages.  Others are entirely new to programming, but very proficient 
with a computer, both with applications and the commandline.  Still 
others know nothing about computers other than how to find a web page.


Describe yourself a little better, and somebody will have a suggestion 
that'll help you at your particular level.  Part of that description 
will include your OS, and the version of Python you're trying to use.



Generically speaking, find a tutorial that fits your level, and that 
matches the version of Python you're experimenting on (2.x or 3.x), and 
dig in.  Do all the exercises, and don't skip ahead if you don't 
understand something.  Either study it till you do, or ask a question 
somewhere.  At the least, make an explicit note, so you'll know what to 
come back to, to fill in the gaps.


Still generically, find an interactive environment that you're 
comfortable with, and experiment.  Python is especially good at that, in 
that you can fire up the interpreter by just typing  python3.3  or 
similar at the shell prompt.


--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Programming for the Absolute Beginner

2013-05-15 Thread Matthew Ngaha
i completed this book and i did every exercise. are you asking for
help with the challenges, or have you completed them and want code to
compare yours too? im relunctant to share challenge code, incase you
havent done them. They are really good exercises to try doing.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread Marc Tompkins
On Wed, May 15, 2013 at 5:07 PM, Steven D'Aprano wrote:


> Guido's time machine strikes again.
>
>
> py> import sys
> py> sys.stdout.write('NOBODY expects the Spanish Inquisition!\n')
> NOBODY expects the Spanish Inquisition!
> 40
>
>
> The write() method of file objects in Python 3 return the number of
> characters written.
>

Awesome!  Thank you Steven; I don't need it today but I suspect I will
shortly.

Meanwhile, for tutees following along at home and wondering what that was
all about: when you do this in an interactive session, as above, it's
confusing.
When you use it in the course of a program, your program doesn't "see" what
gets printed; it only "sees" what gets returned by the function.  So you
would use the return value something like this:

import sys
outString = "NOBODY expects the Spanish Inquisition!\n"
if sys.stdout.write(outString) == len(outString):
print("We're good")
else:
print("Oopsie!")

In other words, if the value returned by write() is the same as the length
of the object you passed to it, the write operation was successful;
otherwise there was a problem and you need to deal with it.

Notice also that you don't _have_ to do anything with the return value; if
you don't assign it to something, or compare it to something (as I did in
my example) it just gets garbage collected and disappears.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Interested in learning Python

2013-05-15 Thread Matthew Ngaha
i recommend getting a copy of Python Programming for the absolute
beginner. It offers end of chapter exercises to make sure you
understand everything you are reading. It was a great read for me and
made my learning experience really fun. I garantee by the end you
would have gained a lot of confidence and will be able to pick up and
learn many new things
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Bugs came home

2013-05-15 Thread Jim Mooney
Just a note about PyScripter since I was whining here about some bugs,
but the bugs were mine ;')

I downloaded Py 64-bit for Py  3.3 but for some reason installed 32
bit for Py 2.7. PyScripter runs multiple Pys but it apparently choked
on the different word lengths. Once I installed 64 bit for both Pys,
the bugs died.  Now I can run Py 2.7 from the Taskbar, since all the
graphics modules and a lot of other kewl stuff are still mostly for
2.7, but continue to explore 3.3 from the Start Menu. PyScripter does
have some nice stuff - multiple Pys, Projects, Debugger, Regex search,
templates, startup scripts, and other useful tools not in Wing unless
you buy the paid version.

But it's easy to use out of the box if you don't want to mess with
that stuff right off. And its folder has a start link for each
installed Py, so you don't have to set anything up except the path to
each Py.

So my bad on the reported PyScripter bugs ;')

--
Jim Mooney
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a Primary Number List generator

2013-05-15 Thread eryksun
On Wed, May 15, 2013 at 8:07 PM, Steven D'Aprano  wrote:
> On 16/05/13 06:02, Alan Gauld wrote:
>>
>> And C's printf() returns the number of chars printed.
>> I actually wish python had followed suit because, as Marc says,
>> it can occasionally be useful...
>
> Guido's time machine strikes again.
>
> py> import sys
> py> sys.stdout.write('NOBODY expects the Spanish Inquisition!\n')
> NOBODY expects the Spanish Inquisition!
> 40
>
> The write() method of file objects in Python 3 return the number of
> characters written.

sys.stdout is a TextIOWrapper, so the return value is the number of
Unicode code points written. If this returns (barring exception), the
return value is guaranteed to be the length of the string; it returns
PyLong_FromSsize_t(textlen).

If you want the number of bytes written, use the underlying
BufferedWriter instead:

>>> sys.stdout.encoding
'UTF-8'
>>> sys.stdout.write('\u0200\n')
Ȁ
2
>>> sys.stdout.buffer.write('\u0200\n'.encode())
Ȁ
3

The return value is the length in bytes. Whatever isn't immediately
written to the file is saved in the buffer to be written later.

Having a return value that's less than the length is possible for
non-buffered IO (not available for text I/O). Here's an example
comparing raw vs buffered I/O after setting a file-size resource limit
of 1000 bytes:

>>> import resource
>>> resource.setrlimit(resource.RLIMIT_FSIZE, (1000, 1000))

An unbuffered FileIO object is immediately honest about the number of
bytes written:

>>> f = open('temp.bin', 'wb', buffering=0)
>>> f.write(b'spam' * 1000)
1000
>>> f.close()

 On the other hand a BufferedWriter will buffer the remaining 3000
bytes that can't be written. You won't find out until an exception is
raised when the file is closed:

>>> f = open('temp.bin', 'wb')
>>> f.write(b'spam' * 1000)
4000
>>> f.close()
Traceback (most recent call last):
  File "", line 1, in 
OSError: [Errno 27] File too large

Regarding built-in print(), you'd have to modify the underlying
PyFile_WriteObject and PyFile_WriteString functions. Currently they
throw away the return object of the file's write() method and instead
return a C int, either 0 (success) or -1 (error). But considering
print() only works with text I/O, for which the underlying write()
simply returns the string length, what's the use case?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Pygraphics crashed

2013-05-15 Thread Jim Mooney
How do I uninstall modules? I installed Pygraphics, which worked fine,
along with some other mods, like numpy, but when I installed 64 bit py
2.7
I get the message "The _imaging C module is not installed" when
running a prog that worked fine before. I think I have a higher
dot-version - Py 2.7.4 as opposed to 2.7.3  - what's the easiest way
to fix this? Will uninstalling and reinstalling the modules do
anything or do I have to revert to an older Py (I'm on Win 7)

And regardless of the answer to that I still want to know how to
uninstall modules. Do I just find and delete them? And are they all in
the same place?

-- 
Jim Mooney
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Can't install latest PIL

2013-05-15 Thread Jim Mooney
Okay, I'm trying to install the latest PIL on win 7. It claims Python
2.7 was not found in the registry, although it's installed, on a path,
and works fine. The install box lets you type in a directory but won't
accept typing. I'm stumped.

I guess the way around this is to know what I have to put in the registry.

-- 
Jim Mooney

“For anything that matters, the timing is never quite right, the
resources are always a little short, and the people who affect the
outcome are always ambivalent.”
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor