Re: Beginner - GUI devlopment in Tkinter - Any IDE with drag and drop feature like Visual Studio?

2013-09-21 Thread shubhxx54
i am very confuse about gui development in python ..
i installed qt creator .. but it has no option for  python..
how can i bulit any app using drag n drop facilities ...
i am trying wxpython ..
plz help me .
how i use wxpython .. 
plzz help me.. 
 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Beginner - GUI devlopment in Tkinter - Any IDE with drag and drop feature like Visual Studio?

2013-09-21 Thread Aseem Bansal
You need to install PySide for GUI development. You don't need Qt Creator. When 
you have PySide installed there is a Qt Designer in your python installation 
directory. You use that for drag and drop GUI development. Search google for 
PySide and you'll find tutorials for that.
-- 
https://mail.python.org/mailman/listinfo/python-list


In Python language, what is (void) referring to?

2013-09-21 Thread Don Sylvia
void...?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: In Python language, what is (void) referring to?

2013-09-21 Thread Chris “Kwpolska” Warrick
On Sat, Sep 21, 2013 at 11:10 AM, Don Sylvia  wrote:
> void...?
> --
> https://mail.python.org/mailman/listinfo/python-list

void does not exist in Python, unless you named a variable “void”.  In
that case, it means whatever you set it to.

-- 
Chris “Kwpolska” Warrick 
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tryign to send mail via a python script by using the local MTA

2013-09-21 Thread Νίκος

On 18/9/2013 2:29 πμ, Dennis Lee Bieber wrote:

On Tue, 17 Sep 2013 18:17:43 +0300, Ferrous Cranus 
declaimed the following:


So cant this be done in python or not?
or is a mtetr of configuring the MTA? conf file?


You can't... Those headers get added by the ISP and any other host the
mail passes through.

The more you fake the originator IP/user the more the subsequent
servers will add flags that they can't confirm who sent the mail... And
eventually some filter may drop it as spam.

Υes Denis every foreign MTA adds headers as mail passes over it ( as 
proved to be done at least from the gmail's smtp)


But if we set up our local MTA to modify the headers, hostname, ip 
address, user) to our own likign then the local MTA will connect to the 
foreign MTA and passes it out modifed data , not the real one.


Ιsn't this possible? that is to fake our hostname and ip address?
--
https://mail.python.org/mailman/listinfo/python-list


Re: In Python language, what is (void) referring to?

2013-09-21 Thread Chris Angelico
On Sat, Sep 21, 2013 at 7:10 PM, Don Sylvia  wrote:
> void...?
> --
> https://mail.python.org/mailman/listinfo/python-list

That looks like a C-style cast, though casting to void is unusual. If
you're looking at the source code to CPython, you might find something
like that. In C it usually means "I don't care about the return value
of this function".

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


How to send an anonymous mail via Python script

2013-09-21 Thread Νίκος

I'll have to ask this atgain because i got no proper reply:
Here is the code i wrote to try tos end anonymous mail:

# 
=

# if html form is submitted then send user mail
# 
=

def random_char( y, chars=string.ascii_uppercase + string.digits ):
return ''.join( random.choice(chars) for x in range(y) )


for times in range(0, 5):
try:
# prepare mail data
FROM = random_char(8) + '@' + 'mail' + '.org'
TO = "[email protected]"

SUBJECT = random_char( 50 )
MESSAGE = random_char( 500 )

		os.system( "echo %s | mailx -v -r %s -s %s %s" % (MESSAGE, FROM, 
SUBJECT, TO) )


		print( "%sη αποστολή προς %s 
επετεύχθη!" % (times, TO) )

except Exception as e:
print( "sendmail => ", date, repr( sys.exc_info() ) )
else:
	print( '''Δεν επιτρέπεται η χρήση του script από μη 
εξουσιοδοτημένα πρόσωπα!''' )


sys.exit(0)
=

Can you please tell me what alternation must be made in order to send 
this anonymously?


that is my question. There must be a way.

1. either by python and its smtplib module
2. by configuring the local MTA
3. by using a remailer

Please provide a solution with code if possible.
I will only answer to serious replies.
--
https://mail.python.org/mailman/listinfo/python-list


Re: In Python language, what is (void) referring to?

2013-09-21 Thread Steven D'Aprano
On Sat, 21 Sep 2013 02:10:49 -0700, Don Sylvia wrote:

> void...?

In Python, void doesn't mean anything.

[steve@ando ~]$ python
Python 2.7.2 (default, May 18 2012, 18:25:10)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> void
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'void' is not defined


What gave you the idea that void was part of Python?


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


Re: How to send an anonymous mail via Python script

2013-09-21 Thread Chris Angelico
On Sat, Sep 21, 2013 at 7:58 PM, Νίκος  wrote:
> Can you please tell me what alternation must be made in order to send this
> anonymously?
>
> that is my question. There must be a way.

No, there isn't. The nearest you could come to anonymous mail would be
sending via a botnet (to hide your IP address) and forging the from
address. So unless you *want* your mail to be flagged as spam and
detested by the entire world, NO THERE IS NO WAY to send it
anonymously.

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


Re: How to send an anonymous mail via Python script

2013-09-21 Thread Νίκος

On 21/9/2013 1:04 μμ, Chris Angelico wrote:

On Sat, Sep 21, 2013 at 7:58 PM, Νίκος  wrote:

Can you please tell me what alternation must be made in order to send this
anonymously?

that is my question. There must be a way.


No, there isn't. The nearest you could come to anonymous mail would be
sending via a botnet (to hide your IP address) and forging the from
address. So unless you *want* your mail to be flagged as spam and
detested by the entire world, NO THERE IS NO WAY to send it
anonymously.

ChrisA


How about an anonymous remailer then?
--
https://mail.python.org/mailman/listinfo/python-list


Re: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it?

2013-09-21 Thread Steven D'Aprano
On Fri, 20 Sep 2013 23:07:57 -0700, William Bryant wrote:

> I am 13 year old beginner in
> python and i am trying to finish the tutorial on code academy and read
> the docs. :)

Hi William, 

I think this is about the fifth or sixth time you've told us this. I'm 
really pleased that a youngster like you is learning to program, but you 
don't have to apologise for your youth in every second email, you're 
starting to make us oldies jealous :-) 

Perhaps when you start a new question, it's okay to remind us. But if 
you're a regular here, we'll soon learn your level of experience.


> def median():
> medlist = List
> medlist.sort()
> if len(medlist) % 2:
> while len(medlist) > 2:
> medlist.popleft()
> medlist.popright()
> if medlist[0] == medlist[1]:
> themedian = medlist
> elif medlist[0] != medlist[1]:
> #make an if statment to figure out the median if the last 2
> left are not the same. Eg [1, 2] the middle value is 1.5
> pass
> else:
> while len(medlist) > 1:
> medlist.popleft()
> medlist.popright()
> themedian = medlist
> return themedian
> 
> It says out of range

If you're going to be a coder, for fun or profit, there are some skills 
you need to learn. One of those skills is to copy and paste the whole 
traceback, not just paraphrase the error message at the end. In this 
case, I can guess what is going wrong without seeing the whole traceback, 
but in general it is best to copy everything from the line

Traceback (most recent call last)

to the end of the error message.

In this case, there is a better approach to calculating the median. Start 
by thinking about how you would calculate it by hand:

* sort the numbers;
* if there is an odd number of items, pick the middle one;
* otherwise pick the two middle ones and take the average.

Python can do the same thing. There's no need to delete items one by one 
from the ends of the list until there are only one, or two left. If you 
have a million items, that would be terribly slow...

So, here we go:

def median():
# Relies on the global variable called List.
List.sort()
n = len(List)
if n % 2 == 1:
# Odd number of items.
return List[n//2]
else:
a = List[n//2 - 1]
b = List[n//2]
return (a + b)/2.0


There's a couple of useful things to learn from this:

1) In a couple of places, you'll see n//2, which looks like division but 
with the / doubled. This is not a typo! It performs integer division, 
throwing away any remainder instead of giving you a fraction. So:

21//7 => 3

22//7 => 3


2) You'll also see a few places where I say List[...] with something 
inside the square brackets. This is looking into the list to grab 
whatever element is in the position. For example:

>>> L = [100, 110, 120, 130]
>>> L[0]  # List indexes start from zero, not one
100
>>> L[1]
110
>>> L[2]
120
>>> L[3]
130


So you can look up the element at any position inside a list in a single 
operation, without needing to throw elements away first. Just remember to 
start counting at zero, not one!


3) Last but not least, the last line divides by 2.0 instead of 2. Why 
2.0? Unfortunately, older versions of Python treat single-slash 
division / differently depending on whether the values have a decimal 
point or not. This was a bad design, and Python 3 has fixed that, but I 
don't know whether you have Python 2 or Python 3. So to be safe, I divide 
by 2.0 to ensure that it calculates the right answer no matter what 
version you are using.



Regards,



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


Re: How to send an anonymous mail via Python script

2013-09-21 Thread Chris Angelico
On Sat, Sep 21, 2013 at 8:15 PM, Νίκος  wrote:
> On 21/9/2013 1:04 μμ, Chris Angelico wrote:
>>
>> On Sat, Sep 21, 2013 at 7:58 PM, Νίκος  wrote:
>>>
>>> Can you please tell me what alternation must be made in order to send
>>> this
>>> anonymously?
>>>
>>> that is my question. There must be a way.
>>
>>
>> No, there isn't. The nearest you could come to anonymous mail would be
>> sending via a botnet (to hide your IP address) and forging the from
>> address. So unless you *want* your mail to be flagged as spam and
>> detested by the entire world, NO THERE IS NO WAY to send it
>> anonymously.
>>
>> ChrisA
>>
> How about an anonymous remailer then?

I'm going to spell this out for the benefit of anyone else who's
reading this, because I know Nikos won't take any notice. This is a
gross oversimplification, but I'm trying to condense everything into a
single email.

The internet can't be built on certainties, so it's built on trust.
Especially with the detection of spam, it's mainly a matter of trust -
trusting the sending computer, trusting the sending domain, and
trusting that the email in question really was sent by that domain.
Most anti-spam measures are aimed at one of those - for instance, SPF
is all about demonstrating that the sending computer belongs to the
sending domain, and DKIM is about matching the contents of the email
to its domain. The receiving MTA has to decide: Do I trust this sender
enough to accept this email, or will I reject it? As an example, my
own mail server checks a lot of things, including:
* How well the sender complies with the SMTP specification (if you
can't get protocol right, I don't want to talk to you; if you
deliberately violate protocol to try to conceal yourself, I definitely
don't want to talk to you)
* Whether the hostname and IP address match
* Whether the reverse DNS for the IP address has four numbers in it (a
common indication of home senders -
c122-107-147-136.eburwd5.vic.optusnet.com.au looks like a home user);
this doesn't prevent mail delivery, but it's marked down
* The SPF record for the sending domain, if it has one
* Certain source or destination addresses that have been blacklisted
* Bayesian similarity to emails previously marked as spam
* A few other details that I won't discuss in public, so you can't
game the system and send me a pile of spam :)

Some of these checks are "below the waterline" requirements - for
instance, if you don't say HELO or EHLO at the beginning of your SMTP
request, I'm not going to accept any mail from you. Others are "above
the waterline" - I'll still take the mail, but it's more likely to go
in the junk folder, because I don't trust you that much.

Violating the internet's standards will often mean your mail gets
rejected. There's a reason for that; trying to hide is usually a bad
idea. Be honest; establish a domain and a (small) set of IP addresses
that send its mail, and you can build up a record of trust ("Every
message I've ever seen from foo.example.com (IP address 203.0.113.54
as per its SPF record) has been accepted by my users as legitimate, so
I'm going to assume that this one, from the same domain and IP, is
legit"). It's not even all that hard to do - just deploy one of the
well-known mail servers like exim or Postfix, set up an SPF record
(not actually necessary, but it's so easy and can help so much that I
think everyone should do it), and let the rest take care of itself.

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


Sphinx Doctest: test the code without comparing the output.

2013-09-21 Thread Luca Cerone
Dear all,
I am writing the documentation for a Python package using Sphinx.

I have a problem when using doctest blocks in the documentation:
I couldn't manage to get doctest to run a command but completely ignoring
the output.

For example, how can I get a doctest like the following to run correctly?

.. doctest:: example_1

   >>> import random
   >>> x = random.uniform(0,100)
   >>> print str(x)
   #some directive here to completely ignore the output

Since I don't know the value of `x`, ideally in this doctest I only want
to test that the various commands are correct, regardless of
the output produced.

I have tried using the ELLIPSIS directive, but the problem is that the `...` 
are interpreted as line continuation rather than `any text`:

.. doctest:: example_2

   >>> import random
   >>> x = random.uniform(0,100)
   >>> print str(x) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
   ...

I don't know if there is a way to make Sphinx understand that I want to ignore 
the whole output. I think the easiest way to solve this, would be 
differentiating between the ellipsis sequence and the line continuation 
sequence, but I don't know how to do that.

I know that I could skip the execution of print(str(x)) but this is not what I 
want; I really would like the command to be executed the output ignored.
Can you point me to any solution for this issue?

Thanks a lot in advance for your help,
Cheers,
Luca
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TypeError: only length-1 arrays can be converted to Python

2013-09-21 Thread Oscar Benjamin
On Sep 21, 2013 7:40 AM, "D.YAN ESCOLAR RAMBAL" 
wrote:
>
> Traceback (most recent call last):
>   File "D:\Yan\Documents\Aptana Studio 3 Workspace\DIF1DMEDYER\SOLUCION
NUMERICA PARA LA ECUACION DE LA DIFUSION EN 1D DYER", line 34, in 
> C=(Cdifuana(M,A,D,x,tinicial))
>   File "D:\Yan\Documents\Aptana Studio 3 Workspace\DIF1DMEDYER\SOLUCION
NUMERICA PARA LA ECUACION DE LA DIFUSION EN 1D DYER", line 32, in Cdifuana
> Cdifuana = (M/temp)*math.exp(-x**2 /(4*D*t))
> TypeError: only length-1 arrays can be converted to Python
>

The math module doesn't work with numpy arrays. You should use numpy.exp()
instead of math.exp().

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


Re: building an online judge to evaluate Python programs

2013-09-21 Thread Modulok
On Fri, Sep 20, 2013 at 11:28 AM, Jabba Laci  wrote:

> Hi,
>
> In our school I have an introductory Python course. I have collected a
> large list of exercises for the students and I would like them to be
> able to test their solutions with an online judge (
> http://en.wikipedia.org/wiki/Online_judge ). At the moment I have a
> very simple web application that is similar to Project Euler: you
> provide the ID of the exercise and the output of the program, and it
> tells you if it's correct or not. However, it can only be used with
> programs that produce an output (usually a short string or a number).
>
> In the next step I would like to do the following. The user can upload
> his/her script, and the system tests it with various inputs and tells
> you if it's OK or not (like checkio.org for instance). How to get
> started with this?
>
> There are several questions:
> * What is someone sends an infinite loop? There should be a time limit.
> * What is someone sends a malicious code? The script should be run in a
> sandbox.
>
> All tips are appreciated.
>
> Thanks,
>
> Laszlo
> --
> https://mail.python.org/mailman/listinfo/python-list



How much time is it worth?

Here's some ideas:

Build a server just for grading student work that contains no valuable data,
probably a virtual server on another machine. Something like virtualBox,
etc.
The code they submit is executed as a less privileged operating system user.
For added security, you could look into using something like FreeBSD process
jails but there's a learning curve there.

I would not be overly concerned with security - put out a bounty as extra
credit:
He who hacks the server through the judge program, and provides details on
how they did it, wins something great, even if it's just class notoriety.

What is someone sends an infinite loop? There should be a time limit:

Run their code as a separate process. If the process or its children run
too long, kill them. On similar grounds you can use operating system
features to define limits on maximum memory, disk usage, maximum number
of
processes, etc. On FreeBSD this can done via the `limits` command, other
operating systems have their own versions of the same thing. Limits are
useful, they prevent things like exhausting physical memory.


What is someone sends a malicious code?

If the server contains no valuable data, there's not much damage they
can
do other than using it for email spam or perhaps shutting it down. You
could prevent email spam by a few firewall rules. To protect the judge
program itself from being hacked set its permission bits to read only.

It is *extremely* difficult to create a sandbox without using operating
system (kernel enforced) features and access controls i.e. permission
bits,
process jails, kernel enforced hardware resource limits, etc. Don't be
tempted to try it without these or you will likely fail.

So long as the student program is run in a process owned by another,
less
privileged system user account, it shouldn't be able to modify the judge
process which started it. For extra security you could even put the
judge
program on its own file system mounted as read-only. The resulting
grades
themselves would have to be stored elsewhere obviously, perhaps another
server that has strict check constraints on what constitutes valid
input no
different than any web service.

You can have yet-another process or even a process on another server
watchdog your judge system. Send it a few test programs every x minutes.
If it fails to respond with the expected results in the expected time
frame
- kill it and restart it. Test again. If it still fails consider it
hacked
(or broken).

Do any graduate students or teacher's assistants owe you favors?
-Modulok-
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sphinx Doctest: test the code without comparing the output.

2013-09-21 Thread Steven D'Aprano
On Sat, 21 Sep 2013 03:47:26 -0700, Luca Cerone wrote:

> Dear all,
> I am writing the documentation for a Python package using Sphinx.
> 
> I have a problem when using doctest blocks in the documentation: I
> couldn't manage to get doctest to run a command but completely ignoring
> the output.
> 
> For example, how can I get a doctest like the following to run
> correctly?
> 
> .. doctest:: example_1
> 
>>>> import random
>>>> x = random.uniform(0,100)
>>>> print str(x)
>#some directive here to completely ignore the output

The Fine Manual says that the directive you want is #doctest:+SKIP.

http://docs.python.org/2/library/doctest.html#doctest.SKIP

Although it's not explicitly listed as a directive, every option flag 
corresponds to a directive. So your example becomes:

>>> import random
>>> x = random.uniform(0,100)
>>> print x  #doctest:+SKIP
42.012345678901234


(There's no need to convert things to str before printing them.)



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


Re: Sphinx Doctest: test the code without comparing the output.

2013-09-21 Thread Luca Cerone
Dear Steven,
thanks for the help.

I am aware that I might have used the SKIP directive (as I hinted in my mail).
Even if the fine manual suggests to do so I don't agree with it, though.
The reason is simple: SKIP as the name suggests causes the code not to be run 
at all, it doesn't ignore the output. If you use a SKIP directive on code that 
contains a typo, or maybe you changed
the name of a keyword to make it more meaningful and forgot to update your 
docstring, then the error won't be caught.

For example:

.. doctest:: example

   >>> printt "Hello, World!" # doctest: +SKIP
   "Hello, World!"

would pass the test. Since I am writing a tutorial for people that have even 
less experience than me with Python, I want be sure that the code in my 
examples runs just fine.

> 
> (There's no need to convert things to str before printing them.)
>

You are right, I modified an example that uses x in one of my functions that 
requires a string in input, and didn't change that.

Thanks again for the help anyway,

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


Re: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it?

2013-09-21 Thread Dave Angel
On 21/9/2013 02:07, William Bryant wrote:

In addition to Steven's comments:

>
> def median():
> medlist = List
> medlist.sort()

You have just altered the original list.  Perhaps sorting it is
harmless, but below you actually remove elements from it.  One way to
avoid that is to use the sorted() method, which creates a new list.

> if len(medlist) % 2:

This then is the "odd" size branch of code.  I think you intended to do
the reverse if-test.  A comment would be in order.

> while len(medlist) > 2:
> medlist.popleft()
> medlist.popright()

At this point, there is exactly one item left in the list.  So the code
below is going to get into trouble.

> if medlist[0] == medlist[1]:
> themedian = medlist

Is the return value of this function supposed to be a list, or a float? 
If a float, then you should be doing something like:
   themedian = medlist[0]

> elif medlist[0] != medlist[1]:
> #make an if statment to figure out the median if the last 2 left 
> are not the same. Eg [1, 2] the middle value is 1.5
> pass
> else:
> while len(medlist) > 1:
> medlist.popleft()
> medlist.popright()
> themedian = medlist
> return themedian
>
> It says out of range and i don't know how I am going to make an if statment 
> to figure out the median if the last 2 left are not the same. Eg [1, 2] the 
> middle value is 1.5. Thanks - I am 13 year old beginner in python and i am 
> trying to finish the tutorial on code academy and read the docs. :)

Taking Steven's suggested code, and changing it so it uses a COPY of the
global list;

def median():
# Relies on the global variable called List.
# assumes there is at least one number in that list
numbers = List.sorted()
n = len(numbers)
if n % 2 == 1:
# Odd number of items.
return numbers[n//2]
else:
a = numbers[n//2 - 1]
b = numbers[n//2]
return (a + b)/2.0

-- 
DaveA


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


Re: Beginner - GUI devlopment in Tkinter - Any IDE with drag and drop feature like Visual Studio?

2013-09-21 Thread Dave Angel
On 21/9/2013 03:19, [email protected] wrote:

> i am very confuse about gui development in python ..
> i installed qt creator .. but it has no option for  python..
> how can i bulit any app using drag n drop facilities ...
> i am trying wxpython ..
> plz help me .
> how i use wxpython .. 
> plzz help me.. 
>  

You mention three different GUI toolkits:

1) subject line says Tkinter
2) you say wxpython
3) your qt creator is presumably connected with qt

You need to get some consistent set of tools.

-- 
DaveA


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


Re: Tryign to send mail via a python script by using the local MTA

2013-09-21 Thread William Ray Wing
On Sep 21, 2013, at 5:21 AM, Νίκος  wrote:

> On 18/9/2013 2:29 πμ, Dennis Lee Bieber wrote:
>> On Tue, 17 Sep 2013 18:17:43 +0300, Ferrous Cranus 
>> declaimed the following:
>> 
>>> So cant this be done in python or not?
>>> or is a mtetr of configuring the MTA? conf file?
>> 
>>  You can't... Those headers get added by the ISP and any other host the
>> mail passes through.
>> 
>>  The more you fake the originator IP/user the more the subsequent
>> servers will add flags that they can't confirm who sent the mail... And
>> eventually some filter may drop it as spam.
>> 
> Υes Denis every foreign MTA adds headers as mail passes over it ( as proved 
> to be done at least from the gmail's smtp)
> 
> But if we set up our local MTA to modify the headers, hostname, ip address, 
> user) to our own likign then the local MTA will connect to the foreign MTA 
> and passes it out modifed data , not the real one.
> 
> Ιsn't this possible? that is to fake our hostname and ip address?
> -- 
> https://mail.python.org/mailman/listinfo/python-list

Νίκος ,
  You CLEARLY don't understand.  Please.  There are Mail headers and there are 
IP packet network headers.  They have to agree with each other or spam/malware 
alarms go off.  Even if you fake the mail headers, there is no way you can use 
fake IP packet headers, they are necessary for the underlying network hardware 
to work.

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


THE MORAL SYSTEM IN ISLAM

2013-09-21 Thread bv4bv4bv4
THE MORAL SYSTEM IN ISLAM
 

 

Islam has laid down universal fundamental rights for humanity that are to be 
observed and respected under all circumstances. In order to realise these 
rights in one's everyday social life, Islam provides both legal safeguards and 
a very effective moral system. In brief, whatever improves the well-being of an 
individual or a society is morally good, and whatever harms this well-being is 
morally bad.

 

 

Islam attaches great importance to the love of God and fellow human beings, and 
discourages excessive formalism. We read in the Quran (what means): “It is not 
righteousness that you turn your faces towards East or West, but [true] 
righteousness is [in] one who believes in Allaah, the Last Day, the Angels, the 
Book, and the prophets and gives wealth, in spite of love for it, to relatives, 
orphans, the needy, the traveller, those who ask [for help], and for freeing 
slaves; [and who] establishes prayer and gives Zakaah; [those who] fulfil their 
promise when they promise; and [those who] are patient in poverty and hardship 
and during battle. Those are the ones who have been true, and it is those who 
are the righteous.” [Quran: 2:177]

 

 

These verses give a beautiful description of the righteous and religiously 
committed individual. He should obey salutary regulations but fix his gaze on 
the love of God and the love of humanity. An individual's faith should be true 
and sincere and he must be prepared to show it in deeds of charity to other 
people and by living as a good citizen and supporter of social organisations. 
Finally, individual faith must remain firm and unshaken in all circumstances.

 

 

This is the standard by which a particular mode of conduct can be classified as 
either good or bad. It also provides the nucleus around which an individual's 
and society’s moral code should revolve. Before laying down any moral 
injunctions, Islam seeks to implant firmly in man's heart the conviction that 
his dealings are with God, Who sees him at all times and in all places. While 
he may hide himself from others or deceive them, he cannot do so with God.

 

 

Islam teaches that the objective of one's life is to live a life that is 
pleasing to God. To make such a goal possible, Islam has provided humankind 
with the highest possible standard of morality. This moral code, which is both 
straightforward and practical, provides the individual with innumerable ways to 
embark upon and then continue the path of moral evolution. By making Divine 
Revelation the primary source of knowledge, moral standards are made permanent 
and stable. However, this does not make them inflexible, for there is room for 
reasonable adjustment and adaptation when needed. The danger of moral 
relativism, now so widespread in many societies, is thereby avoided.

 

 

Another benefit is the gradual internalisation of these moral standards, for 
one seeks to obey them voluntarily to please God, not because some government 
or people tell him to do so. An individual's belief in God, when added to his 
belief in the Day of Judgement, is a powerful motivating factor to live a 
highly moral life.

 

 

Islam does not seek to minimise the importance of traditional and

commonly accepted moral norms or give exaggerated importance to some and 
neglect others.

 

 

The Islamic moral code incorporates all the commonly accepted moral virtues and 
then endows them with a sense of balance and proportion, by assigning each one 
a suitable place and function in the scheme of life. It widens the scope of 
man's individual and collective life by dealing with his domestic associations, 
civic conduct, and his activities in the political, economic, legal, 
educational and social realms. It covers his life from the home to the society, 
from the dining table to the battlefield and peace conferences. In short, from 
the cradle to the grave - for no sphere of life is exempt from the universal 
and comprehensive application of the moral principles of Islam. It makes 
morality reign supreme and ensures that the affairs of life are regulated by 
moral norms, and not dominated by selfish desires and petty interests.

 

 

A major goal of Islam is to provide humankind with a practical and realistic 
system of life by which he can conduct his life. It calls upon humankind not 
only to practice virtue, but also to establish it and to eradicate all that is 
harmful. It seeks the supremacy of the conscience in all matters so that what 
is harmful cannot gain the upper hand either in an individual's life or in 
society. Those who respond to this call are known as Muslims, which literally 
means those who have submitted to God. The sole object of the resulting 
community of Muslims or Ummah is undertaking an organised effort to establish 
what is good and to fight and eradicate what is evil and harmful.

 

 

Some of Islam's basic moral teachings are given below. They cover the broad 
spectrum of a Muslim's 

Re: Sphinx Doctest: test the code without comparing the output.

2013-09-21 Thread Steven D'Aprano
On Sat, 21 Sep 2013 05:44:09 -0700, Luca Cerone wrote:

> If you use a SKIP
> directive on code that contains a typo, or maybe you changed the name of
> a keyword to make it more meaningful and forgot to update your
> docstring, then the error won't be caught.

And if you ignore the output, the error won't be caught either. What's 
the difference?


>>> 1 + 1  #doctest:+IGNORE_OUTPUT  (not a real directive)
1000

Since doctest is ignoring the output, it won't catch the failure. Even if 
your code raises an exception, if you ignore the output, you'll never see 
the exception because it is ignored.

So you simply can't do what you want. You can't both ignore the output of 
a doctest and have doctest report if the test fails.


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


Re: How to send an anonymous mail via Python script

2013-09-21 Thread Joel Goldstick
On Sat, Sep 21, 2013 at 6:41 AM, Chris Angelico  wrote:

> On Sat, Sep 21, 2013 at 8:15 PM, Νίκος  wrote:
> > On 21/9/2013 1:04 μμ, Chris Angelico wrote:
> >>
> >> On Sat, Sep 21, 2013 at 7:58 PM, Νίκος  wrote:
> >>>
> >>> Can you please tell me what alternation must be made in order to send
> >>> this
> >>> anonymously?
> >>>
> >>> that is my question. There must be a way.
>

Nikos, stop!  There very well may be a way to send spam.  But you need to
understand internet infrastructure, and be more clever than the many people
who do understand the internet infrastructure and don't want to read spam.
You can't do this because, as you have professed in other endless trolling
threads,  you don't like to read or study, you like people to give you
answers.  To me, that is the definition of laziness.  The second reason you
can't do this may be that you just don't want to do any of the things you
ask here.  Evidence of this would be that you repeat the same questions
over and over, ignore the answers, quote other's as supporting your
ruefully annoying wining, and then start a new thread just like the old
thread with one of your many email aliases.  That is the definition of a
troll.

This list is very informative when you disappear for a while.  If your
purpose is to single handedly degrade the experience of dozens of people
with interesting questions, and volunteers who guide and teach others, well
nice job.  If by chance you are just an unfortunate soul with such large
gaps in your self understanding of how rude your behavior here is, you
should know that you are rude. So, stop it




> >>
> >>
> >> No, there isn't. The nearest you could come to anonymous mail would be
> >> sending via a botnet (to hide your IP address) and forging the from
> >> address. So unless you *want* your mail to be flagged as spam and
> >> detested by the entire world, NO THERE IS NO WAY to send it
> >> anonymously.
> >>
> >> ChrisA
> >>
> > How about an anonymous remailer then?
>
> I'm going to spell this out for the benefit of anyone else who's
> reading this, because I know Nikos won't take any notice. This is a
> gross oversimplification, but I'm trying to condense everything into a
> single email.
>
> The internet can't be built on certainties, so it's built on trust.
> Especially with the detection of spam, it's mainly a matter of trust -
> trusting the sending computer, trusting the sending domain, and
> trusting that the email in question really was sent by that domain.
> Most anti-spam measures are aimed at one of those - for instance, SPF
> is all about demonstrating that the sending computer belongs to the
> sending domain, and DKIM is about matching the contents of the email
> to its domain. The receiving MTA has to decide: Do I trust this sender
> enough to accept this email, or will I reject it? As an example, my
> own mail server checks a lot of things, including:
> * How well the sender complies with the SMTP specification (if you
> can't get protocol right, I don't want to talk to you; if you
> deliberately violate protocol to try to conceal yourself, I definitely
> don't want to talk to you)
> * Whether the hostname and IP address match
> * Whether the reverse DNS for the IP address has four numbers in it (a
> common indication of home senders -
> c122-107-147-136.eburwd5.vic.optusnet.com.au looks like a home user);
> this doesn't prevent mail delivery, but it's marked down
> * The SPF record for the sending domain, if it has one
> * Certain source or destination addresses that have been blacklisted
> * Bayesian similarity to emails previously marked as spam
> * A few other details that I won't discuss in public, so you can't
> game the system and send me a pile of spam :)
>
> Some of these checks are "below the waterline" requirements - for
> instance, if you don't say HELO or EHLO at the beginning of your SMTP
> request, I'm not going to accept any mail from you. Others are "above
> the waterline" - I'll still take the mail, but it's more likely to go
> in the junk folder, because I don't trust you that much.
>
> Violating the internet's standards will often mean your mail gets
> rejected. There's a reason for that; trying to hide is usually a bad
> idea. Be honest; establish a domain and a (small) set of IP addresses
> that send its mail, and you can build up a record of trust ("Every
> message I've ever seen from foo.example.com (IP address 203.0.113.54
> as per its SPF record) has been accepted by my users as legitimate, so
> I'm going to assume that this one, from the same domain and IP, is
> legit"). It's not even all that hard to do - just deploy one of the
> well-known mail servers like exim or Postfix, set up an SPF record
> (not actually necessary, but it's so easy and can help so much that I
> think everyone should do it), and let the rest take care of itself.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/ma

Re: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it?

2013-09-21 Thread MRAB

On 21/09/2013 13:53, Dave Angel wrote:
[snip]

Taking Steven's suggested code, and changing it so it uses a COPY of the
global list;

def median():
 # Relies on the global variable called List.
 # assumes there is at least one number in that list
 numbers = List.sorted()


That should be:

 numbers = sorted(List)


 n = len(numbers)
 if n % 2 == 1:
 # Odd number of items.
 return numbers[n//2]
 else:
 a = numbers[n//2 - 1]
 b = numbers[n//2]
 return (a + b)/2.0



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


Re: Sphinx Doctest: test the code without comparing the output.

2013-09-21 Thread Luca Cerone
> And if you ignore the output, the error won't be caught either. What's 
> 
> the difference?
> 
> >>> 1 + 1  #doctest:+IGNORE_OUTPUT  (not a real directive)
> 
> 1000
> 
> 

The difference is that in that case you want to check whether the result is 
correct or not, because you expect a certain result.

In my case, I don't know what the output is, nor care for the purpose of the 
tutorial. What I care is being sure that the command in the tutorial is 
correct, and up to date with the code.

If you try the following, the test will fail (because there is a typo in the 
code)

.. doctest:: example

   >>> printt "hello, world"

and not because the output doesn't match what you expected.

Even if the command is correct:

.. doctest:: example_2

   >>> print "hello, world"

this text will fail because doctest expects an output. I want to be able to 
test that the syntax is correct, the command can be run, and ignore whatever 
the output is.

Don't think about the specific print example, I use this just to show what the 
problem is, which is not what I am writing a tutorial about!

> 
> 
> So you simply can't do what you want. You can't both ignore the output of 
> 
> a doctest and have doctest report if the test fails.
> 

OK, maybe it is not possible using doctest. Is there any other way to do what I 
want? For example using an other Sphinx extension??
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why does it have red squiggly lines under it if it works perfectly fine and no errors happen when I run it?

2013-09-21 Thread Dave Angel
On 21/9/2013 12:18, MRAB wrote:

> On 21/09/2013 13:53, Dave Angel wrote:
> [snip]
>> Taking Steven's suggested code, and changing it so it uses a COPY of the
>> global list;
>>
>> def median():
>>  # Relies on the global variable called List.
>>  # assumes there is at least one number in that list
>>  numbers = List.sorted()
>
> That should be:
>
>   numbers = sorted(List)

OOPS.  Thanks, you're so right.

-- 
DaveA


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


Code suggestions?

2013-09-21 Thread Benjamin Schollnick
Folks,

I am re-writing an image gallery application that I wrote in Twisted.

As part of this rewrite, I am attempting to simplify the process of managing 
the directory listings.

Would anyone have any suggestions on streamlining or optimizing this code?

The raw version of this file, is available from dropbox.

https://dl.dropboxusercontent.com/u/241415/unified.py

If you are testing with RAR files, you'll need rarfile.py

https://dl.dropboxusercontent.com/u/241415/rarfile.py

If anyone knows a better built-in Python 2.66/2.75 solution, that would be 
helpful.  

I eventually expect to support caching, but I think that will be an application 
level feature, and not built-in to this module.

The entire idea is to unify (thus unified.py) behavior better files, 
directories, and archives.

Yes, there is differences in the data coming back, but the calling logic, is 
identical.

So far, this rewrite has tremendously simplified the code for the image 
gallery.  If there is any interest, I'm willing to github unified or the image 
gallery.  

- Benjamin

import os
import os.path
from stat import *
import time
class   Unified_Directory:
"""
An Attempt to unify directories, and archives into one single 
storage package.

For example:

gallery_listings = unified.Unified_Directory ()

gallery_listings.populate_file_data_from_filesystem ( filepathname = 
directory_path)
print "files: ",gallery_listings.files,"/n/n"
print "subdirectories: 
",gallery_listings.subdirectories, "/n/n"
print "Display Gallery for ", 
gallery_listings.root_path

"""

def __init__ ( self ):
self.rar_file_types = ['cbr', 'rar']
self.zip_file_types = ['cbz', 'zip']
self.archive_file_types = self.rar_file_types + 
self.zip_file_types

self.files_to_ignore= []#   File 
filter to ignore

self.root_path  = None  #   
This is the path in the OS that is being examined (e.g. 
/Volumes/Users/username/ )
self.subdirectories = []#   This is 
the subdirectories that exist in that path (e.g. Desktop, Music, Videos, etc)


self.files  = []
#   This is the list of files that are in the root_path.

#   Each file consists of a dictionary containing:

#

#   * Filename

#   * st_mode   - Unix chmod

#   * st_ino- inode number

#   * st_dev- Unix Device

#   * st_nlink  - hard link count

#   * st_uid- User/Owner ID

#   * st_gid- Group ID of Owner

#   * st_size   - File size

#   * st_atime  - Last Access time

#   * st_mtime  - Last Modified Time

#   * st_ctime  - Last Metadata change

#   * dot_extension - File extension with . 
prefix (lower case)

#   * file_extension- File Extension 
without . prefix (lower case)

   

Re: Code suggestions?

2013-09-21 Thread MRAB

On 21/09/2013 15:00, Benjamin Schollnick wrote:

Folks,

I am re-writing an image gallery application that I wrote in Twisted.

As part of this rewrite, I am attempting to simplify the process of
managing the directory listings.

Would anyone have any suggestions on streamlining or optimizing this code?

The raw version of this file, is available from dropbox.

https://dl.dropboxusercontent.com/u/241415/unified.py

If you are testing with RAR files, you'll need rarfile.py

https://dl.dropboxusercontent.com/u/241415/rarfile.py

If anyone knows a better built-in Python 2.66/2.75 solution, that would
be helpful.

I eventually expect to support caching, but I think that will be an
application level feature, and not built-in to this module.

The entire idea is to unify (thus unified.py) behavior better files,
directories, and archives.

Yes, there is differences in the data coming back, but the calling
logic, is identical.

So far, this rewrite has tremendously simplified the code for the image
gallery.  If there is any interest, I'm willing to github unified or the
image gallery.


[snip]
Some comments:-

Using "import *" is generally regarded as a Bad Thing.

Class names usually don't contain underscores, therefore
"UnifiedDirectory" would be better.

It's better to create file paths using os.path.join(...) instead of
"manually" using "+".

When checking for None, use "is" and "is not", not "==" and "!=".

It's almost NEVER a good idea to use a bare except. Specify which
exception you're trying to catch.

The function "populate_file_data_from_filesystem" can return True,
False (printing a message just before it does so, which makes it harder
to use as part of a library), or None (because there's a bare return).
It would be better if it raised an exception in the case of an error,
returning None otherwise (a bare return).

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


Re: building an online judge to evaluate Python programs

2013-09-21 Thread Ned Batchelder

On 9/21/13 3:57 PM, Jabba Laci wrote:

Hi Ned,

Could you please post here your AppArmor profile for restricted Python scripts?
Laszlo, the instructions are in the README, including the AppArmor 
profile.  It isn't much:


#include 

/bin/python {
#include 
#include 

/** mr,
# If you have code that the sandbox must be able to access, add lines
# pointing to those directories:
/the/path/to/your/sandbox-packages/** r,

/tmp/codejail-*/ rix,
/tmp/codejail-*/** rix,
}

Note that there are other protections beyond AppArmor, setrlimits is also used 
to limit some resource use.

--Ned.

BTW: Top-posting makes it harder to follow threads of conversations, better 
form is to add your comments below the person you're replying to.


Thanks,

Laszlo

On Sat, Sep 21, 2013 at 12:46 AM, Ned Batchelder  wrote:

On 9/20/13 6:26 PM, Jabba Laci wrote:

I just found Docker ( http://docs.docker.io/en/latest/faq/ ). It seems
sandboxing could be done with this easily.


At edX, I wrote CodeJail (https://github.com/edx/codejail) to use AppArmor
to run Python securely.

For grading Python programs, we use a unit-test like series of challenges.
The student writes problems as functions (or classes), and we execute them
with unit tests (not literally unittest, but a similar idea).  We also
tokenize the code to check for simple things like, did you use a while loop
when the requirement was to write a recursive function.  The grading code is
not open-source, unfortunately, because it is part of the MIT courseware.

--Ned.


Laszlo

On Fri, Sep 20, 2013 at 10:08 PM, John Gordon  wrote:

In  Jabba Laci
 writes:


There are several questions:
* What is someone sends an infinite loop? There should be a time limit.

You could run the judge as a background process, and kill it after ten
seconds if it hasn't finished.


* What is someone sends a malicious code? The script should be run in a
sandbox.

You could run the judge from its own account that doesn't have access to
anything else.  For extra security, make the judge program itself owned
by
a separate account (but readable/executable by the judge account.)

I suppose you'd have to disable mail access from the judge account too.
Not sure how to easily do that.

--
John Gordon   A is for Amy, who fell down the stairs
[email protected]  B is for Basil, assaulted by bears
  -- Edward Gorey, "The Gashlycrumb
Tinies"

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




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


Re: building an online judge to evaluate Python programs

2013-09-21 Thread Jabba Laci
Hi Ned,

Could you please post here your AppArmor profile for restricted Python scripts?

Thanks,

Laszlo

On Sat, Sep 21, 2013 at 12:46 AM, Ned Batchelder  wrote:
> On 9/20/13 6:26 PM, Jabba Laci wrote:
>>
>> I just found Docker ( http://docs.docker.io/en/latest/faq/ ). It seems
>> sandboxing could be done with this easily.
>
>
> At edX, I wrote CodeJail (https://github.com/edx/codejail) to use AppArmor
> to run Python securely.
>
> For grading Python programs, we use a unit-test like series of challenges.
> The student writes problems as functions (or classes), and we execute them
> with unit tests (not literally unittest, but a similar idea).  We also
> tokenize the code to check for simple things like, did you use a while loop
> when the requirement was to write a recursive function.  The grading code is
> not open-source, unfortunately, because it is part of the MIT courseware.
>
> --Ned.
>
>> Laszlo
>>
>> On Fri, Sep 20, 2013 at 10:08 PM, John Gordon  wrote:
>>>
>>> In  Jabba Laci
>>>  writes:
>>>
 There are several questions:
 * What is someone sends an infinite loop? There should be a time limit.
>>>
>>> You could run the judge as a background process, and kill it after ten
>>> seconds if it hasn't finished.
>>>
 * What is someone sends a malicious code? The script should be run in a
 sandbox.
>>>
>>> You could run the judge from its own account that doesn't have access to
>>> anything else.  For extra security, make the judge program itself owned
>>> by
>>> a separate account (but readable/executable by the judge account.)
>>>
>>> I suppose you'd have to disable mail access from the judge account too.
>>> Not sure how to easily do that.
>>>
>>> --
>>> John Gordon   A is for Amy, who fell down the stairs
>>> [email protected]  B is for Basil, assaulted by bears
>>>  -- Edward Gorey, "The Gashlycrumb
>>> Tinies"
>>>
>>> --
>>> https://mail.python.org/mailman/listinfo/python-list
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


reload and work flow suggestions

2013-09-21 Thread Peter Cacioppi
This is an idea brought over from another post.

When I write Python code I generally have 2 or 3 windows open simultaneously.

1) An editor for the actual code.
2) The interactive interpreter.
3) An editor for the unit tests. (Sometimes skipped for quick one-off scripts)

My work flow tends to involve using 2 to debug the issues that come up with 1 
and 3. I'll write some new code in 1, play around with it in 2, then solidify 
the tests in 3. Or a test in 3 fails and I dig around with it using 2.

My problem is that I tend to use reload() quite a bit. I want to call functions 
and construct objects that are inside the guts of 1 and pass them arguments 
that are stored as variables in 2. If I restart my session for 2 I lose these 
variables (iPython does mitigate the pain here somewhat). Hence, I reload() 
modules into 2 when they are changed.

I use ipdb a lot in 2. I usually don't feel comfortable with virgin code or a 
debug fix that hasn't been stepped through with the debugger.

Is there something wrong with this work flow? I understand most python experts 
avoid reload(). So what are they doing that I'm not? I love the ability of 
Python to quickly let you dive deep into your code and set up a difficult case 
with 2, it's hard to imagine giving this up, and it's hard to imagine using it 
without reload(). 

Thanks for any tips.

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


Re: reload and work flow suggestions

2013-09-21 Thread Terry Reedy

On 9/21/2013 5:43 PM, Peter Cacioppi wrote:

This is an idea brought over from another post.

When I write Python code I generally have 2 or 3 windows open simultaneously.

1) An editor for the actual code.
2) The interactive interpreter.
3) An editor for the unit tests. (Sometimes skipped for quick one-off scripts)


At present, I use an Idle Shell and two editor windows.


My work flow tends to involve using 2 to debug the issues that come up with 1 
and 3. I'll write some new code in 1, play around with it in 2, then solidify 
the tests in 3. Or a test in 3 fails and I dig around with it using 2.


F5 in an editor window runs the code, puts the results in Shell, and 
leaves the objects loaded for interactive exploration in Shell.



My problem is that I tend to use reload() quite a bit. I want to call functions 
and construct objects that are inside the guts of 1 and pass them arguments 
that are stored as variables in 2. If I restart my session for 2 I lose these 
variables (iPython does mitigate the pain here somewhat). Hence, I reload() 
modules into 2 when they are changed.


Since I work with files small enough to reload by rerunning, I have no 
use for reload().



I use ipdb a lot in 2. I usually don't feel comfortable with virgin code or a 
debug fix that hasn't been stepped through with the debugger.


I trust tests, formal and informal, and use occasional print to debug.


Is there something wrong with this work flow? I understand most python experts 
avoid reload(). So what are they doing that I'm not? I love the ability of 
Python to quickly let you dive deep into your code and set up a difficult case 
with 2, it's hard to imagine giving this up, and it's hard to imagine using it 
without reload().


Since 'experts do not use Idle', I must not be one ;-). I will let the 
real 'experts' explain what they do.


--
Terry Jan Reedy

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


Re: Making it a MultiThread!

2013-09-21 Thread Piet van Oostrum
stas poritskiy  writes:

>> I am working on integration of multiple GUI (Tkinter) elements, such
>> a progress bar, label update, etc, and throughout my research i
>> discovered that i need to have Threading modules used to distribute
>> the calls for GUI update and processing of my main App.

In general your GUI should be in your main process/thread. For example
your program doesn't run on Mac OS X because you cannot run the GUI in
another process or thread.

Now if your GUI actions are starting some actions that last more than a
few tenths of a second, you should run these actions in another thread
or process (usually a thread will work), otherwise the GUI becomes
unresponsive. If you want to exchange some information between the GUI
and that thread/process you can use a Queue object, or just give the
information from the GUI at the start of the thread.

>> My Application is broken into multiple Classes(modules), and i wanted
>> to hear your thought on the best practices to implement the Threading
>> model.

The structure of you modules isn't good. There are circular imports, and
that is a sign the the design needs to be simplified:

multiProcessLauncher imports gui.
gui imports multiProcessLauncher.

The latter import isn't necessary. 

Instead of

import multiProcessLauncher
processor = multiProcessLauncher
name = processor.multiprocessing.current_process().name

you can just use:

import multiprocessing
name = multiprocessing.current_process().name

My advice would be to just do the GUI in the main module, and if the
Action needs more time, the create a new Thread or Process in the Action
class.

-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Making it a MultiThread!

2013-09-21 Thread Chris Angelico
On Sun, Sep 22, 2013 at 11:00 AM, Piet van Oostrum  wrote:
> Now if your GUI actions are starting some actions that last more than a
> few tenths of a second, you should run these actions in another thread...

Hmm. When I first learned GUI programming (on OS/2), the advice was
one tenth of a second absolute maximum, or spin off a thread. But yes,
the advice is the same. Keep your main thread REALLY responsive.

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


Re: Sphinx Doctest: test the code without comparing the output.

2013-09-21 Thread Chris Angelico
On Sun, Sep 22, 2013 at 2:25 AM, Luca Cerone  wrote:
> The difference is that in that case you want to check whether the result is 
> correct or not, because you expect a certain result.
>
> In my case, I don't know what the output is, nor care for the purpose of the 
> tutorial. What I care is being sure that the command in the tutorial is 
> correct, and up to date with the code.

I'd call that a smoke-test, rather than something a test
harness/engine should be doing normally. All you do is see if the
program crashes. This can be extremely useful (I smoke-test my scripts
as part of my one-key "deploy to testbox" script, saving me the
trouble of actually running anything - simple syntactic errors or
misspelled function/variable names (in languages where that's a
concept) get caught really early); but if you're using this for a
tutorial, you risk creating a breed of novice programmers who believe
their first priority is to stop the program crashing. Smoke testing is
a tool that should be used by the expert, NOT a sole check given to a
novice.

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


Re: Sphinx Doctest: test the code without comparing the output.

2013-09-21 Thread Steven D'Aprano
On Sat, 21 Sep 2013 09:25:26 -0700, Luca Cerone wrote:

>> And if you ignore the output, the error won't be caught either. What's
>> the difference?
>> 
>> >>> 1 + 1  #doctest:+IGNORE_OUTPUT  (not a real directive)
>> 1000
>> 
>> 
> The difference is that in that case you want to check whether the result
> is correct or not, because you expect a certain result.
> 
> In my case, I don't know what the output is, nor care for the purpose of
> the tutorial. What I care is being sure that the command in the tutorial
> is correct, and up to date with the code.
> 
> If you try the following, the test will fail (because there is a typo in
> the code)
> 
> .. doctest:: example
> 
>>>> printt "hello, world"
> 
> and not because the output doesn't match what you expected.


That is not how doctest works. That test fails because its output is:

SyntaxError: invalid syntax


not because doctest recognises the syntax error as a failure. Exceptions, 
whether they are syntax errors or some other exception, can count as 
doctest *successes* rather than failures. Both of these count as passing 
doctests:


>>> x++  # Python is not C!
Traceback (most recent call last):
  ..
SyntaxError: unexpected EOF while parsing

>>> 1/0
Traceback (most recent call last):
  ..
ZeroDivisionError: division by zero


Consequently, doctest only recognises failures by their output, 
regardless of whether that output is a value or an exception.


> Even if the command is correct:
> 
> .. doctest:: example_2
> 
>>>> print "hello, world"
> 
> this text will fail because doctest expects an output. I want to be able
> to test that the syntax is correct, the command can be run, and ignore
> whatever the output is.

The only wild-card output that doctest recognises is ellipsis, and like 
all wild-cards, can match too much if you aren't careful. If ellipsis is 
not matching exactly what you want, add some scaffolding to ensure a 
match:

   >>> import random
   >>> x = random.uniform(0,100)
   >>> print "x =", x  # doctest:+ELLIPSIS
   x = ...


will work. But a better solution, I think, would be to pick a 
deterministic result:

>>> import random
>>> random.seed(100)
>>> random.uniform(0, 100)
14.566925510413032


Alas, that only works reliably if you stick to a single Python version. 
Although the results of calling random.random are guaranteed to be stable 
across versions, random functions build on top of random.random like 
uniform are not and may need to be protected with a version check.



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


Re: reload and work flow suggestions

2013-09-21 Thread Westley Martínez
On Saturday, September 21, 2013 2:43:13 PM UTC-7, Peter Cacioppi wrote:
> This is an idea brought over from another post.
> 
> 
> 
> When I write Python code I generally have 2 or 3 windows open simultaneously.
> 
> 
> 
> 1) An editor for the actual code.
> 
> 2) The interactive interpreter.
> 
> 3) An editor for the unit tests. (Sometimes skipped for quick one-off scripts)
> 
> 
> 
> My work flow tends to involve using 2 to debug the issues that come up with 1 
> and 3. I'll write some new code in 1, play around with it in 2, then solidify 
> the tests in 3. Or a test in 3 fails and I dig around with it using 2.
> 
> 
> 
> My problem is that I tend to use reload() quite a bit. I want to call 
> functions and construct objects that are inside the guts of 1 and pass them 
> arguments that are stored as variables in 2. If I restart my session for 2 I 
> lose these variables (iPython does mitigate the pain here somewhat). Hence, I 
> reload() modules into 2 when they are changed.
> 
> 
> 
> I use ipdb a lot in 2. I usually don't feel comfortable with virgin code or a 
> debug fix that hasn't been stepped through with the debugger.
> 
> 
> 
> Is there something wrong with this work flow? I understand most python 
> experts avoid reload(). So what are they doing that I'm not? I love the 
> ability of Python to quickly let you dive deep into your code and set up a 
> difficult case with 2, it's hard to imagine giving this up, and it's hard to 
> imagine using it without reload(). 
> 
> 
> 
> Thanks for any tips.

In short, there's nothing wrong with any workflow so long as it works.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sphinx Doctest: test the code without comparing the output.

2013-09-21 Thread Luca Cerone
> but if you're using this for a
> 
> tutorial, you risk creating a breed of novice programmers who believe
> 
> their first priority is to stop the program crashing. Smoke testing is

Hi Chris,
actually my priority is to check that the code is correct. I changed the syntax 
during the development, and I want to be sure that my tutorial is up to date.

The user will only see the examples that, after testing with doctest, will
run. They won't know that I used doctests for the documentation..

How can I do what you call smoke tests in my Sphinx documentation?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sphinx Doctest: test the code without comparing the output.

2013-09-21 Thread Luca Cerone
> 
> That is not how doctest works. That test fails because its output is:

ok.. is there a tool by which I can test if my code runs regardless the output?

> 
> The only wild-card output that doctest recognises is ellipsis, and like 
> 
> all wild-cards, can match too much if you aren't careful. If ellipsis is 
>

actually I want to match the whole output.. and you can't because ellipsis is 
the same as line continuation...
> 
> 
> 
> will work. But a better solution, I think, would be to pick a 

I think you are sticking too much to the examples I posted, where I used 
functions that are part of Python, so that everybody could run the code and 
test the issues.

I don't use random numbers, so I can't apply what you said.
Really, I am looking for a way to test the code while ignoring the output.

I don't know if usually it is a bad choice, but in my case is what I want/need.

Thanks for the help,
Luca
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sphinx Doctest: test the code without comparing the output.

2013-09-21 Thread Chris Angelico
On Sun, Sep 22, 2013 at 2:09 PM, Luca Cerone  wrote:
>> but if you're using this for a
>>
>> tutorial, you risk creating a breed of novice programmers who believe
>>
>> their first priority is to stop the program crashing. Smoke testing is
>
> Hi Chris,
> actually my priority is to check that the code is correct. I changed the 
> syntax
> during the development, and I want to be sure that my tutorial is up to date.
>
> The user will only see the examples that, after testing with doctest, will
> run. They won't know that I used doctests for the documentation..
>
> How can I do what you call smoke tests in my Sphinx documentation?

I don't know Sphinx, so I can't help there. But maybe you should just
have a pile of .py files, and you import each one and see if you get
an exception?

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


Why do I have to use "global" so much when using Turtle?

2013-09-21 Thread John Ladasky
Hi, folks,

Some of you may remember that I am teaching some high school students how to 
program.  Because they all love graphics, I have been investigating the turtle 
module, which I gather is built on top of Tk.  I can see that real-time 
applications are possible.  I'm writing a classic "bouncing-balls" program to 
demonstrate to my students.  

In the main program code, I instantiate a turtle.Screen, named sc.  

I draw a bounding box, whose size is described by the variables edgew and 
edgeh.  I have a list of Turtle objects, which I named balls.  I have a timer 
interval stored in tick.

In the main loop of my program, I bind a function to update the positions of 
the balls to a timer, thus:

sc.ontimer(move_balls, tick)

Inside my move_balls function, I could not get ANYTHING done without the 
following declaration:

global balls, edgew, edgeh, tick

For a while, I had a "quit" function that I bound to the q key:

sc.onkeypress(quit, "q")

The quit function simply printed a message, and then called sc.bye().  As with 
move_balls, quit wouldn't work unless I had a "global sc" declaration in it.  
(My shortened program skips my function and just binds sc.bye to the q key, 
avoiding the need for globals.)

Once I use globals, everything works fine.  However, I haven't taught my 
students a thing about the globals declaration.  Furthermore, I was always 
taught that the need for global variables generally indicated that YOU were 
writing a SLOPPY program!

However, neither Screen.ontimer() not Screen.onkeypress() appear to give me a 
way to pass arguments to functions of my own.  Why don't they?  Is this some 
limitation of Tk?  I have worked with other GUI's before, and I don't remember 
having to jump through this particular hoop.

I'm torn between proceeding with turtle, burdening my students with 
comprehending globals (they're young, they just barely grasp the idea of 
namespaces) -- or, abandoning turtle for another approach.

Comments appreciated!
-- 
https://mail.python.org/mailman/listinfo/python-list