Newbie: unexpected indenting error

2014-07-13 Thread Martin S
While coding a rating calculator I am using a for-loop within if-elif-else.
When using the for-loop in the first if instance my editor accepts
this, but when using the same for-loop within the elif instance it
complain about "unexpected indent".

Like so:

def function(x):
   if rdiff >=500:
  for 
 [do stuff]
   elif rdiff >=410:
   for ...  <== unexpected indent
  [do other stuff]


What the...? What am I doing wrong?
(hopefully the indents translate; else def, if/elif, for and [dostuff]
are indented)

/Martin S
-- 
Regards,

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


Re: Newbie: unexpected indenting error

2014-07-13 Thread Ben Finney
Martin S  writes:

> What the...? What am I doing wrong?
> (hopefully the indents translate; else def, if/elif, for and [dostuff]
> are indented)

They're all indented by different amounts. I don't see anything that
would cause the parser to tell you “unexpected indent”, though.

For those reasons together, I suspect what you've posted here does not
match exactly what is in your Python code.

My recommendation:

* Instruct your text editor to highlight any U+0009 characters
  (horizontal tab) as an error, and remove them. Indent with U+0020
  SPACE characters only; PEP 8 recommends four spaces per indent level.

* Ensure your emails are composed in plain text (AFAICT, you're already
  doing this), and show us *exactly* a complete example of code that
  will demonstrate the behaviour you're seeing. Make a new one, if you
  need to; just make sure it's complete so you can expect others to be
  able to run it too.

-- 
 \  “If I haven't seen as far as others, it is because giants were |
  `\   standing on my shoulders.” —Hal Abelson |
_o__)  |
Ben Finney

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


Re: Newbie: unexpected indenting error

2014-07-13 Thread Mark Lawrence

On 13/07/2014 08:01, Martin S wrote:

While coding a rating calculator I am using a for-loop within if-elif-else.
When using the for-loop in the first if instance my editor accepts
this, but when using the same for-loop within the elif instance it
complain about "unexpected indent".

Like so:

def function(x):
if rdiff >=500:
   for 
  [do stuff]
elif rdiff >=410:
for ...  <== unexpected indent
   [do other stuff]


What the...? What am I doing wrong?
(hopefully the indents translate; else def, if/elif, for and [dostuff]
are indented)

/Martin S



You've gone A Space Too Far.

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


Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


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


Re: Newbie: unexpected indenting error

2014-07-13 Thread Martin S
Thanks, the problem was apparently a mix of way to indent the code.
It's confused the H out of the editor. Using standard indentation
solved the error.

2014-07-13 9:28 GMT+02:00 Gary Herron :
> On 07/13/2014 12:01 AM, Martin S wrote:
>>
>> While coding a rating calculator I am using a for-loop within
>> if-elif-else.
>> When using the for-loop in the first if instance my editor accepts
>> this, but when using the same for-loop within the elif instance it
>> complain about "unexpected indent".
>>
>> Like so:
>>
>> def function(x):
>> if rdiff >=500:
>>for 
>>   [do stuff]
>> elif rdiff >=410:
>> for ...  <== unexpected indent
>>[do other stuff]
>>
>>
>> What the...? What am I doing wrong?
>> (hopefully the indents translate; else def, if/elif, for and [dostuff]
>> are indented)
>>
>> /Martin S
>
>
> The code looks OK, but looks can be deceiving if you've manage to mix tabs
> and spaces to achieve that.
>
> Check for a mixture, and settle on one.  Tabs would work, but the
> recommendation is to use spaces.
>
> If you don't have a mixture of the two, then we have a mystery. Send your
> file as an attachment, and we'll take a closer look at it.
>
> Gary Herron
>
>
>
> --
> Dr. Gary Herron
> Department of Computer Science
> DigiPen Institute of Technology
> (425) 895-4418
>



-- 
Regards,

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


Twitter Client on Terminal by Python

2014-07-13 Thread Orakaro
Hello!

I'm @dtvd88 on Twitter and very new here.
I read from python.org that anything Python-related can be discussed, and not 
sure if I can share my OSS package here to get feedback or not ?

I just wrote a Twitter Client on Terminal by Python, it has very beautiful 
display and even can display image on terminal. Check it out and maybe you guys 
will love it :)

Homepage: http://www.rainbowstream.org/
Github: https://github.com/DTVD/rainbowstream

Thanks for any feedback and sorry if this kind of topics is not tolerated here.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Twitter Client on Terminal by Python

2014-07-13 Thread Chris Angelico
On Mon, Jul 14, 2014 at 4:00 AM, Orakaro  wrote:
> Thanks for any feedback and sorry if this kind of topics is not tolerated 
> here.

No no, announcements of this sort are perfectly welcome here!

I notice you have both README.md and README.rst - is there a reason for that?

What Python versions does rainbowstream support? Your README hints
that both 2.x and 3.x are supported, but I can't see a specific set of
versions (eg "2.6+, 3.3+").

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


What Next After Python Basics

2014-07-13 Thread Orochi
Hi,
I am beginner in Python
I have Completed Basic Python Course from Codecademy.com .
Now that I have a hands on the basics what is the next thing I should do.
I mean should I learn more or start a small Project(Any Ideas are Welcomed) or 
any Other suggestions.
Where to Start?

Thank You,
Orochi
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: codingbat question broken?

2014-07-13 Thread Orochi
On Sunday, 13 July 2014 07:49:18 UTC+5:30, Chris Angelico  wrote:
> On Sun, Jul 13, 2014 at 12:05 PM, Rodrick Brown  
> wrote:
> 
> >
> 
> > Can anyone show me an example where all test are success?
> 
> 
> 
> No, because that's asking for the answer :) What you need to do is
> 
> look at the failing test cases, and figure out why your function is
> 
> giving the wrong result. Do you see what's true of all the failing
> 
> cases and is not true of any others? That might give you a clue as to
> 
> what's wrong.
> 
> 
> 
> ChrisA



On Sunday, 13 July 2014 07:49:18 UTC+5:30, Chris Angelico  wrote:
> On Sun, Jul 13, 2014 at 12:05 PM, Rodrick Brown  
> wrote:
> 
> >
> 
> > Can anyone show me an example where all test are success?
> 
> 
> 
> No, because that's asking for the answer :) What you need to do is
> 
> look at the failing test cases, and figure out why your function is
> 
> giving the wrong result. Do you see what's true of all the failing
> 
> cases and is not true of any others? That might give you a clue as to
> 
> what's wrong.
> 
> 
> 
> ChrisA

This Is My Code(using Python 2.7)
Its working fine with the given test cases.
#Lucky_Sum
a =[]
def lucky_sum(list):
t = 0
for item in list:
if item == 13:
break
else:
t=t+item
return t

list=[]
type(list)
n = raw_input("Enter Numebr of item in list: ")
n = int(n)

for x in range (0,n):
list.append(int(raw_input()))
print "List is :",list

print lucky_sum(list)
-- 
https://mail.python.org/mailman/listinfo/python-list


Multiprocessing question

2014-07-13 Thread Paul LaFollette
Kind people,
I have thrown together a little C/UNIX program that forks a child process,
then proceeds to let the child and parent alternate.  Either can run until
it pauses itself and wakes the other.

I would like to know if there be a way to create the same behavior in
Python 3, preferably in a non-platform dependent fashion.  I would prefer
to use processes rather than threads, but could live with threads if I had
to.  I've studied the documentation for the multiprocessing and thread
modules, but I can't see an easy way to do what I want to do.  I need
minimal communication between processes beyond what i have described, so
creating queues or pipes seems like overkill.  Unlike what I have written
here, I will want to exec the child rather than write the whole thing in
the else clause.  Is there a reasonably simple way to do this?  A reference
to useful documentation would be appreciated.  Sample code even more so, of
course.
Thank you
Paul

-
Paul S. LaFollette, Jr
CIS Department
Temple University
+1 215 204 6822
paul.lafolle...@temple.edu
http://knight.cis.temple.edu/~lafollet

#include 
#include 
#include 
#include 
#include 
#include 

int main(int argc, char **argv)
{
  void handler(int);
  pid_t pid;

  signal(SIGCONT, handler);

  pid = fork();
  if (pid < 0) //failure
  {
printf("Unable to fork\n");
exit(1);
  }
  else if (pid > 0) // parent
  {
while (1)
{
  printf("Parent waiting for child to do something\n");
  pause();
  printf("Parent doing nifty stuff.\n");
  sleep(1);
  printf("Parent waking child\n");
  errno = 0;
  if (kill(pid, SIGCONT) < 0)
perror("Parent failed to SIGCONT child.");
}
  }
  else //pid == 0 so child
  {
while (1)
{
  printf ("Child doing useful
work.\n");
  sleep(1);
  printf(" Child waking parent\n");
  if (kill(getppid(), SIGCONT) < 0)
perror("Child failed to SIGCONT parent.");
  printf(" Child waiting for parent
to do something\n");
  pause();
}
  }
}

void handler(int signum)
{
}
===
Output:
Parent waiting for child to do something
Child doing useful work.
 Child waking parent
 Child waiting for parent to do
something
Parent doing nifty stuff.
Parent waking child
Parent waiting for child to do something
Child doing useful work.
 Child waking parent
 Child waiting for parent to do
something
Parent doing nifty stuff.
Parent waking child
Parent waiting for child to do something
Child doing useful work.
 Child waking parent
 Child waiting for parent to do
something
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Newbie: unexpected indenting error

2014-07-13 Thread Denis McMahon
On Sun, 13 Jul 2014 09:01:12 +0200, Martin S wrote:

> While coding a rating calculator I am using a for-loop within
> if-elif-else.
> When using the for-loop in the first if instance my editor accepts this,
> but when using the same for-loop within the elif instance it complain
> about "unexpected indent".
> 
> Like so:
> 
> def function(x):
>if rdiff >=500:
>   for 
>  [do stuff]
>elif rdiff >=410:
>for ...  <== unexpected indent
>   [do other stuff]
> 
> 
> What the...? What am I doing wrong?
> (hopefully the indents translate; else def, if/elif, for and [dostuff]
> are indented)

You seem to have posted what you believe is an equivalent structure to 
your code, rather than your actual code.

The structure you have posted looks fine, but it's not a runnable snippet 
that we can actually test.

Can you actually reproduce the problem in a single block of code that we 
can try and run ourselves?

For example, if you copy your "problem" function to a new file and edit 
the function def line and the code and lines after the for statements as 
follows, does the problem persist?

for rdiff in range( 450, 600, 100 ):
   if rdiff >=500:
  for i in range( 1, 3 ):
 print rdiff, i
   elif rdiff >=410:
  for i in range( 1, 3 ):
 print i, ridff

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


Re: Multiprocessing question

2014-07-13 Thread Gary Herron

On 07/13/2014 04:53 PM, Paul LaFollette wrote:

Kind people,
I have thrown together a little C/UNIX program that forks a child 
process, then proceeds to let the child and parent alternate.  Either 
can run until it pauses itself and wakes the other.


I would like to know if there be a way to create the same behavior in 
Python 3, preferably in a non-platform dependent fashion.  I would 
prefer to use processes rather than threads, but could live with 
threads if I had to.  I've studied the documentation for the 
multiprocessing and thread modules, but I can't see an easy way to do 
what I want to do.  I need minimal communication between processes 
beyond what i have described, so creating queues or pipes seems like 
overkill.  Unlike what I have written here, I will want to exec the 
child rather than write the whole thing in the else clause.  Is there 
a reasonably simple way to do this?  A reference to useful 
documentation would be appreciated.  Sample code even more so, of course.

Thank you
Paul


There is a quite reasonable way to do what you want,  but that involves 
the multiprocessing and queue modules, both of which you have eliminated 
from consideration.


So you have to ask yourself:  What do you gain from using Python if you 
eliminate all the tools Python provides?


Gary Herron






-
Paul S. LaFollette, Jr
CIS Department
Temple University
+1 215 204 6822
paul.lafolle...@temple.edu 
http://knight.cis.temple.edu/~lafollet 



#include 
#include 
#include 
#include 
#include 
#include 

int main(int argc, char **argv)
{
  void handler(int);
  pid_t pid;

  signal(SIGCONT, handler);

  pid = fork();
  if (pid < 0) //failure
  {
printf("Unable to fork\n");
exit(1);
  }
  else if (pid > 0) // parent
  {
while (1)
{
  printf("Parent waiting for child to do something\n");
  pause();
  printf("Parent doing nifty stuff.\n");
  sleep(1);
  printf("Parent waking child\n");
  errno = 0;
  if (kill(pid, SIGCONT) < 0)
perror("Parent failed to SIGCONT child.");
}
  }
  else //pid == 0 so child
  {
while (1)
{
  printf ("Child doing useful 
work.\n");

  sleep(1);
  printf(" Child waking 
parent\n");

  if (kill(getppid(), SIGCONT) < 0)
perror("Child failed to SIGCONT parent.");
  printf(" Child waiting for 
parent to do something\n");

  pause();
}
  }
}

void handler(int signum)
{
}
===
Output:
Parent waiting for child to do something
Child doing useful work.
 Child waking parent
 Child waiting for parent to do 
something

Parent doing nifty stuff.
Parent waking child
Parent waiting for child to do something
Child doing useful work.
 Child waking parent
 Child waiting for parent to do 
something

Parent doing nifty stuff.
Parent waking child
Parent waiting for child to do something
Child doing useful work.
 Child waking parent
 Child waiting for parent to do 
something






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


Re: What Next After Python Basics

2014-07-13 Thread Dan Stromberg
On Sun, Jul 13, 2014 at 1:16 PM, Orochi  wrote:
> Hi,
> I am beginner in Python
> I have Completed Basic Python Course from Codecademy.com .
> Now that I have a hands on the basics what is the next thing I should do.
> I mean should I learn more or start a small Project(Any Ideas are Welcomed) 
> or any Other suggestions.
> Where to Start?

That really depends on how quickly (or slowly) you get frustrated.

If you're able to say "I don't understand this yet, but I'll tuck it
in the back of my mind for later" a lot, and google for answers as
needed, I'd dive into a project.

If not, maybe try another course and/or monitor this group and Stackoverflow.

The best kind of project to pick, now or later, is the kind that you
will actually use yourself.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What Next After Python Basics

2014-07-13 Thread C.D. Reimer

On 7/13/2014 1:16 PM, Orochi wrote:

Hi,
I am beginner in Python
I have Completed Basic Python Course from Codecademy.com .
Now that I have a hands on the basics what is the next thing I should do.
I mean should I learn more or start a small Project(Any Ideas are Welcomed) or 
any Other suggestions.
Where to Start?

Thank You,
Orochi


My first project after barely learning the basics of Python was reading 
a spreadsheet with 600+ website URLs, taking a screenshot of each 
website, and building a HTML webpage to display the 600+ screenshots. If 
I was to do this manually (i.e., clicking and looking at each website), 
this would take two weeks of my spare time. By automating this task into 
a Python script (which took two weeks of my spare time), the script runs 
for two hours in the background and I take 15 minutes to glance at the 
HTML pages with screenshots. If I find something wrong with a particular 
screenshot, I can click on the website URL to investigate further.


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


Re: Twitter Client on Terminal by Python

2014-07-13 Thread Orakaro
On Monday, July 14, 2014 3:20:43 AM UTC+9, Chris Angelico wrote:
> On Mon, Jul 14, 2014 at 4:00 AM, Orakaro  wrote:
> 
> > Thanks for any feedback and sorry if this kind of topics is not tolerated 
> > here.
> 
> 
> 
> No no, announcements of this sort are perfectly welcome here!
> 
> 
> 
> I notice you have both README.md and README.rst - is there a reason for that?
> 
> 
> 
> What Python versions does rainbowstream support? Your README hints
> 
> that both 2.x and 3.x are supported, but I can't see a specific set of
> 
> versions (eg "2.6+, 3.3+").
> 
> 
> 
> ChrisA

Hi Angelico 

I use README.md for Github and README.rst for PyPi. Is there a way to use only 
one file for both sites ?

I tested my package on Python 2.7 and Python 3.4 But do I have to install all 
Python 2.6, Python 3.* in my system and test in all environment for sure ?

Thanks very much. 

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


Re: Multiprocessing question

2014-07-13 Thread Steven D'Aprano
On Sun, 13 Jul 2014 19:53:09 -0400, Paul LaFollette wrote:

> I have thrown together a little C/UNIX program that forks a child
> process, then proceeds to let the child and parent alternate.  Either
> can run until it pauses itself and wakes the other.
> 
> I would like to know if there be a way to create the same behavior in
> Python 3, preferably in a non-platform dependent fashion.

The most direct way of duplicating the Unix idiom of forking a child 
process is to use the os.fork function, which is (I believe) just a thin 
wrapper around the C fork function.

https://docs.python.org/3/library/os.html#os.fork


But this is not platform-independent, it is Unix only.

Alternatively, you can look at the various os.exec* functions, which are 
available on Windows and Unix, and see if any of them are useful.

But the best way to solve this in a platform independent way is to use 
one of the concurrency modules:

https://docs.python.org/3/library/concurrency.html

such as multiprocessing. Although these are written for Python 2 rather 
than 3, you may find them useful:

http://pymotw.com/2/multiprocessing/index.html#module-multiprocessing

https://www.ibm.com/developerworks/aix/library/au-multiprocessing/


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


Re: Twitter Client on Terminal by Python

2014-07-13 Thread Chris Angelico
On Mon, Jul 14, 2014 at 12:18 PM, Orakaro  wrote:
> I use README.md for Github and README.rst for PyPi. Is there a way to use 
> only one file for both sites ?

Ah. I don't know; check the docs for one or the other and see what they'll do.

> I tested my package on Python 2.7 and Python 3.4 But do I have to install all 
> Python 2.6, Python 3.* in my system and test in all environment for sure ?

You can state that it supports 2.7 and 3.4, without testing on any
other versions. Those are the two current versions - my example was
showing support for more than just the one latest, but that was just
an example, nothing more. When Python 3.5 comes out, you'll probably
want to test on that (and then say "supports 2.7 and 3.4+"), but at
the moment, "2.7 and 3.4" is fine. If people want to use this with,
say, 3.3, then they're welcome to try, but they'll know not to presume
that it'll work.

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


Re: Twitter Client on Terminal by Python

2014-07-13 Thread Orakaro
On Monday, July 14, 2014 12:51:29 PM UTC+9, Chris Angelico wrote:
> On Mon, Jul 14, 2014 at 12:18 PM, Orakaro  wrote:
> 
> > I use README.md for Github and README.rst for PyPi. Is there a way to use 
> > only one file for both sites ?
> 
> 
> 
> Ah. I don't know; check the docs for one or the other and see what they'll do.
> 
> 
> 
> > I tested my package on Python 2.7 and Python 3.4 But do I have to install 
> > all Python 2.6, Python 3.* in my system and test in all environment for 
> > sure ?
> 
> 
> 
> You can state that it supports 2.7 and 3.4, without testing on any
> 
> other versions. Those are the two current versions - my example was
> 
> showing support for more than just the one latest, but that was just
> 
> an example, nothing more. When Python 3.5 comes out, you'll probably
> 
> want to test on that (and then say "supports 2.7 and 3.4+"), but at
> 
> the moment, "2.7 and 3.4" is fine. If people want to use this with,
> 
> say, 3.3, then they're welcome to try, but they'll know not to presume
> 
> that it'll work.
> 
> 
> 
> ChrisA

 Angelico, Thank you very much!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Multiprocessing question

2014-07-13 Thread Marko Rauhamaa
Gary Herron :

> On 07/13/2014 04:53 PM, Paul LaFollette wrote:
>> I have thrown together a little C/UNIX program that forks a child
>> process, then proceeds to let the child and parent alternate. Either
>> can run until it pauses itself and wakes the other.
>>
>> [...]
>
> What do you gain from using Python if you eliminate all the tools
> Python provides?

The language core itself.

Anyway, the subprocessing.Popen is perfect for process creation. For
event multiplexing, Python3.4 has the asyncio module, although
multiplexing pipes might be platform-dependent (works in linux at
least).


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


Logging all uncaught exceptions

2014-07-13 Thread Steven D'Aprano
I want to catch all uncaught exceptions in my application, log them, then 
handle as normal. Which, in practice, means a traceback. Is this the 
right way to do it?



import logging
import sys

logger = logging.getLogger('mylogger')

def my_handler(type, value, tb):
msg = "Uncaught %s: %s" % (type, value)
logger.exception(msg)
sys.__excepthook__(type, value, tb)


# Install exception handler
sys.excepthook = my_handler

# Run your main script here:
if __name__ == '__main__':
main()


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