Re: [Tutor] Help

2018-05-16 Thread Alan Gauld via Tutor
On 16/05/18 02:43, Steven D'Aprano wrote:

> The traceback Sam posted says (in part):
> 
>   Move = input('What Will You Do? Fight or Run: ')
>   File "", line 1, in 
>   NameError: name 'Run' is not defined
> 
> so the failed line was the call to input(). In Python 3, it would return 
> a string. In Python 2, input() evaluates whatever the user types as 
> code, hence I infer Sam typed:
> 
> Run
> 
> and input() tries to evaluate it, which fails.


Shneaky!
I was trying to figure out why the traceback highlighted
that line instead of the if... I never thought about it
being a Python 2 issue.

Good catch!

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


[Tutor] Python Question

2018-05-16 Thread Mahamed Ahmed
Hello,

Please I would like you to help me solve the problem above which is related to 
loops and prime numbers so please get back to me, I also want to know how to 
sign up and get a online tutor for this python course

Here is what is supposed to be done:
The prime numbers and their code has already been given but what is need to be 
done is making the lines and correcting it in a organized way
If you run the code above, you’ll see the result then will just need to make 
the small lines and writing Line1,Line2,Line3,Line4 and Line 5 at the left side 
of the list

Hope you understand what the problem is about and  would love to hear about you

Regards[cid:image002.jpg@01D3ECD5.44D97ED0]

Sent from Mail for Windows 10

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


[Tutor] redirecting testing output to file, using two different options

2018-05-16 Thread Yosef Levy
Hello All,

I have testing environment.
Code is written under Python 2.6.
testing output should be redirected to log file.
I am using two different file handling, in order to log output:



1. logging module:

import unittest2
import logging
import sys

class TestMyEnvClass (unittest2.TestCase):
def setUp (self):
pass
def testMyEnv (self):
logging.debug  ( "In testMyEnv.." )
def tearDown (self):
pass

if __name__ == "__main__":
logging.basicConfig( filename='log_file.txt', stream=sys.stderr,
level=logging.DEBUG)
logging.getLogger( "TestMyEnvClass.testMyEnv" ).setLevel( logging.DEBUG
)
unittest2.main()


running:
python test.py

output:
# cat log_file.txt
DEBUG:root:In testMyEnv..
#





2. but if I want to redirect assert messages to file, I have to:

import unittest2

class TestMyEnvClass (unittest2.TestCase):
def setUp (self):
pass
def testMyEnv (self):
res = True
self.assertEqual(res, True, 'Testing my environment..')
def tearDown (self):
pass

if __name__ == "__main__":
f = open('log_file.txt', "a")
runner = unittest2.TextTestRunner(f)
unittest2.main(testRunner=runner)
f.close ()



running:
# python test2.py

output:
# cat log_file.txt
.
--
Ran 1 test in 0.000s

OK



Question:
Is the a way to 'merge' the above two different ways output to file?
Or, is there a way to redirect assert messages to logging module methods?


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


Re: [Tutor] Python Question

2018-05-16 Thread Mats Wichmann
On 05/15/2018 03:26 PM, Mahamed Ahmed wrote:
> Hello,
> 
> Please I would like you to help me solve the problem above which is related 
> to loops and prime numbers so please get back to me, I also want to know how 
> to sign up and get a online tutor for this python course
> 
> Here is what is supposed to be done:
> The prime numbers and their code has already been given but what is need to 
> be done is making the lines and correcting it in a organized way
> If you run the code above, you’ll see the result then will just need to make 
> the small lines and writing Line1,Line2,Line3,Line4 and Line 5 at the left 
> side of the list
> 
> Hope you understand what the problem is about and  would love to hear about 
> you

I am afraid there is no code or description.  If you sent it as a link
to an image, it did not survive through email.

If you can paste the code into a new message, people here will be happy
to comment on it - that's the way this (volunteer) effort works, by the
way: we don't want to solve your homework problems for you, but if you
show what you have done and what the question or error is, people are
happy to help with that.

As far as finding a personal tutor for a Python course, that's a
different problem and I'm afraid we can't help with that. There are
people providing that kind of service (for a fee, I'm sure), should be
able to find through some internet searching.

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


Re: [Tutor] Python Question

2018-05-16 Thread Alan Gauld via Tutor
On 15/05/18 22:26, Mahamed Ahmed wrote:
> Please I would like you to help me solve the problem above 

We see no problem. this is a text only list so if you included
a binary attachment the server will have stripped it off for
security reasons.

Please repost the text of the problem description and any code
using plain text not HTML (since HTML will lose the code formatting)

> I also want to know how to sign up and get a online tutor for 
> this python course

We will comment on your code and answer questions but we
don't do one on one mentoring. Also we don't know your course.
But if you post any questions here we will do our best to
assist you.

> Here is what is supposed to be done:
> The prime numbers and their code has already been given but> what is need to 
> be done is making the lines and correcting > it in a
organized way.

One of the first things you learn about programming is that
the more clearly you can explain the problem (even to yourself)
the easier it is to find an answer in code. Avoid vague and woolly
descriptions.

What exactly does "making the lines" and "correcting it in an
organized way" mean?
What do the lines look like?
What is organized about it?
How is it "corrected"?

English may not be your first language and if that is the case
try explaining it in your language first before translating
into English (or even into Python). The important step is
getting the requirement absolutely clear in your own head.

> If you run the code above, 

We can't see the code.

> just need to make the small lines and writing Line1,Line2,...
> at the left side of the list

So what does "make the small lines mean? How small?
What should they contain?

> Hope you understand what the problem is

Sorry, but without the original problem statement or
code and with only your description to go on it is impossible
to know what you need.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: [Tutor] redirecting testing output to file, using two different options

2018-05-16 Thread Alan Gauld via Tutor
On 16/05/18 09:53, Yosef Levy wrote:
> Hello All,
> 
> I have testing environment.
> Code is written under Python 2.6.
> testing output should be redirected to log file.

You don't say which OS you are using but if it's a
Unix variant you could just use command line
redirection of stdout/stderr. That is probably
the simplest option and requires no code changes.

I think asserts and the logging module both
use stderr by default. At least I would hope that
they do!

Redirect stderr to a logfile with

$ python myscript.py arg1 arg2...argn 2> mylogfile.txt

Windows supports redirection too but I don't recall
how (or if) you can isolate stderr...

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


Re: [Tutor] redirecting testing output to file, using two different options

2018-05-16 Thread Mats Wichmann
On 05/16/2018 02:53 AM, Yosef Levy wrote:
> Hello All,
> 
> I have testing environment.
> Code is written under Python 2.6.

Why? 2.6 was retired in October 2013.  For long life of your code you
should be using Python 3, but at least 2.7 is still current and getting
updates (for another 18 months or so).


> testing output should be redirected to log file.
> I am using two different file handling, in order to log output:
> 
> 
> 
> 1. logging module:

> 2. but if I want to redirect assert messages to file, I have to:
> 
> import unittest2

> Question:
> Is the a way to 'merge' the above two different ways output to file?
> Or, is there a way to redirect assert messages to logging module methods?

If you use pytest, this should be fairly straightforward. It normally
captures stdout and stderr (the latter should have your asserts), and
with a plugin, puts logging output on the same basis, so you get get
everything going the same place:

https://pypi.org/project/pytest-catchlog/#description
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor