Label behavior's difference between tkinter and ttk

2016-04-05 Thread ast

Hello

I currently migrate a GUI from tkinter to ttk and I found a problem

Here is a piece of code, with comments which explain what is 
wrong.


import tkinter as tk
import tkinter.ttk as ttk

root = tk.Tk()

BITMAP0 = """
#define zero_width 24
#define zero_height 32
static char zero_bits[] = {
0x00,0x00,0x00, 0x00,0x00,0x00, 0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f,
0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00,
0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f,
0x00,0x00,0x00, 0x00,0x00,0x00, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f,
0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00,
0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f,
0x00,0x00,0x00, 0x00,0x00,0x00, 0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f,
0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00
};
"""

img = tk.BitmapImage(data=BITMAP0, foreground='white', background='black')

# This Label comes from ttk

label = ttk.Label(root, image=img)

# This Label comes from tk. To be uncommented to test behavior'difference
# label = tk.Label(root, image=img)

label.pack()

# The graphic is not refreshed after entering following commands
# when Label comes from ttk. You have to fly over the label with 
# the mouse to get the right color.

# The graphic is immediately updated when Label comes from tk

# Enter these commands by hand, in a shell

img.config(foreground='red')
img.config(foreground='lime')
img.config(foreground='yellow')


It looks like a ttk bug, isn't it ?
I am using python 3.5.1

I tried a root.update_idletasks() to refresh the graphic
but it changed nothings.

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


Promoting Python

2016-04-05 Thread Gordon( Hotmail )
I am struggling to understand the basic principles of Python having spent many 
years as a pure Amateur tinkering with a variety of BASIC  as you can see on my 
site at http://www.sigord.co.uk/  I think you will agree all such versions of 
Basic I have used are far easier to understand than Python. Though with my 
limited knowledge I accept Python may have many advantages over say Liberty 
Basic etc.

The problem I am finding is most of the sites claiming to help understand 
Python devote far too much space bragging about the wonders of Python instead 
of concentrating how to make sensible use of it. For example I struggle to find 
examples of such as below if you could please help me. If I manage to duplicate 
some of my efforts on my site with Python I will be happy to upload the code to 
my site. I will also try to upload working exec files of such also, except my 
previous attempts at downloading the relevant software was blocked by AVG 
software as risky. 

Gordon


Liberty Basic
for n = 32 to 255: print n;chr$(n) : next n

REM BBC Basic
FOR c = 1 TO 15 : COLOUR c
  PRINT "Color ";c
NEXT c

REM BBC Basic
c = 0
FOR x = 80 TO 2000 STEP 96
  GCOL c: CIRCLE FILL x,500,50 : c = c + 1
NEXT x

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


Re: module alias in import statement

2016-04-05 Thread Steven D'Aprano
On Tuesday 05 April 2016 14:27, Rustom Mody wrote:

> On Tuesday, April 5, 2016 at 9:53:30 AM UTC+5:30, Chris Angelico wrote:
>> On Tue, Apr 5, 2016 at 2:08 PM, Rustom Mody  wrote:
>> >> 'import tk.ttk' looks for 'tk' in sys.modules, does not find it, looks
>> >> for a module named 'tk' on disk, does not find it, and says so.
>> >
>> > A well-known quote comes to mind:
>> >
>> > | There are only two hard things in Computer Science: cache
>> > | invalidation and naming things.
>> >
>> > eg. http://martinfowler.com/bliki/TwoHardThings.html
>> >
>> > particularly since this seems to be in both categories :-)
>> 
>> sys.modules isn't really a cache in that sense, though. The "hard
>> problem" of cache invalidation comes from the fundamental assumption
>> that a cache hit should be semantically identical to a cache miss;
> 
> Following looks like a cache miss to me (certainly did to the OP):
> 
> On Monday, April 4, 2016 at 9:01:41 PM UTC+5:30, ast wrote:
>> hello
>> 
>> >>> import tkinter as tk
>> >>> import tk.ttk as ttk
>> 
>> Traceback (most recent call last):
>>   File "", line 1, in 
>> import tk.ttk as ttk
>> ImportError: No module named 'tk'


But that *miss* isn't cached -- if the OP then created a package called "tk" 
with a submodule called "ttk", and then re-ran the `import tk.ttk as ttk` 
line, the import subsystem would have picked up the newly created package 
and imported it.

I think that's the point Chris was trying to make.



-- 
Steve

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


Re: Request to mailing list Python-list rejected

2016-04-05 Thread Oscar Benjamin
On 5 Apr 2016 03:50,  wrote:
>
> Your request to the Python-list mailing list
>
> Posting of your message titled "Re: Plot/Graph"
>
> has been rejected by the list moderator.  The moderator gave the
> following reason for rejecting your request:
>
> "Your message was too big; please trim unnecessary content."
>
> Any questions or comments should be directed to the list administrator
> at:
>
> [email protected]

When did this start happening?

The message in question includes a big block of code posted by someone else
as context. My comment was that the code was incomplete so I felt it
reasonable to include it as context.

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


Re: Promoting Python

2016-04-05 Thread Rustom Mody
On Tuesday, April 5, 2016 at 12:53:13 PM UTC+5:30, Gordon( Hotmail ) wrote:
> I am struggling to understand the basic principles of Python having spent 
> many years as a pure Amateur tinkering with a variety of BASIC  as you can 
> see on my site at http://www.sigord.co.uk/  I think you will agree all such 
> versions of Basic I have used are far easier to understand than Python. 
> Though with my limited knowledge I accept Python may have many advantages 
> over say Liberty Basic etc.
> 
> The problem I am finding is most of the sites claiming to help understand 
> Python devote far too much space bragging about the wonders of Python instead 
> of concentrating how to make sensible use of it. For example I struggle to 
> find examples of such as below if you could please help me. If I manage to 
> duplicate some of my efforts on my site with Python I will be happy to upload 
> the code to my site. I will also try to upload working exec files of such 
> also, except my previous attempts at downloading the relevant software was 
> blocked by AVG software as risky. 
> 
> Gordon
> 
> 
> Liberty Basic
> for n = 32 to 255: print n;chr$(n) : next n

I grew up on BBC basic in 1984. Not used thereafter.

Your first one is (I guess) this in python:

>>> for i in range(32,127):
...   print chr(i),
... 
  ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G 
H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o 
p q r s t u v w x y z { | } ~

> 
> REM BBC Basic
> FOR c = 1 TO 15 : COLOUR c
>   PRINT "Color ";c
> NEXT c
> 
> REM BBC Basic
> c = 0
> FOR x = 80 TO 2000 STEP 96
>   GCOL c: CIRCLE FILL x,500,50 : c = c + 1
> NEXT x

If you tell us some more of what color, gcol etc do someone will likely show you
Though in all fairness I dont expect it to be as pithy as the BASIC
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: module alias in import statement

2016-04-05 Thread Chris Angelico
On Tue, Apr 5, 2016 at 5:26 PM, Steven D'Aprano
 wrote:
>>> sys.modules isn't really a cache in that sense, though. The "hard
>>> problem" of cache invalidation comes from the fundamental assumption
>>> that a cache hit should be semantically identical to a cache miss;
>>
>> Following looks like a cache miss to me (certainly did to the OP):
>>
>> On Monday, April 4, 2016 at 9:01:41 PM UTC+5:30, ast wrote:
>>> hello
>>>
>>> >>> import tkinter as tk
>>> >>> import tk.ttk as ttk
>>>
>>> Traceback (most recent call last):
>>>   File "", line 1, in 
>>> import tk.ttk as ttk
>>> ImportError: No module named 'tk'
>
>
> But that *miss* isn't cached -- if the OP then created a package called "tk"
> with a submodule called "ttk", and then re-ran the `import tk.ttk as ttk`
> line, the import subsystem would have picked up the newly created package
> and imported it.
>
> I think that's the point Chris was trying to make.

Not quite; that was a separate point (that negative results aren't
cached). A cache miss is when the cache doesn't have something, and
Python goes to the next source (in this case, searching the file
system). The end result should be the same in either case (you get a
module object), but in Python, a cache miss results in *actual code
execution*. Granted, you often still won't *see* any difference (your
typical module just quietly defines a bunch of stuff), but there's
still a significant semantic difference; consider what happens when
you type "import this as that" followed by "import this". The second
one is a cache hit, and it's fundamentally different in function.

Cache invalidation is all about knowing when you should *ignore* the
cached entry and go back to the file system. Python will never do
this, because the semantics are defined very differently.

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


Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-05 Thread Nagy László Zsolt

> Yes, my question is why it's useful to have a single Interval as a
> *distinct* type, separate from the interval set type, which supports a
> sharply limited number of set-like operations (such as the union of two
> overlapping intervals but NOT two non-overlapping ones). This doesn't
> appear to be the case in sympy based on your examples.
The main reason for this was to check begin / end values, and return the
EMPTY_INTERVAL singleton for empty intervals. If we want to support zero
length intervals with begin==end value, then there is no need to use
EMPTY_INTERVAL. But there is still need to check begin <= end. But maybe
you are right: if we suppose that nobody will try to use an interval
where end < begin then we can use plain tuples. But then the user *must*
make sure not to use invalid intervals. Both solution have pros and
cons. Right now, I prefer to find the problem as soon as possible (e.g.
in the Interval constructor), but you can try to convince me.
> Having an interval as a distinct type may be useful (to iterate over the
> intervals of a set, for example), but his design blurs the line between
> intervals and sets (by supporting some set operations) without
> eliminating it as sympy seems to do.
It is blurred by design. There is an interpretation where an interval
between [0..4] equals to a set of intervals ([0..2],[2..4]). Actually,
you can ask: "is an element within the interval?" The same question can
be asked for an Interval set. So the same type of value can be
"contained" within an interval and also witin an interval set. In the
current implementation, if you try to create a set with these two
intervals [0..2] and [2..4], then they are unified into a single element
on purpose: to make sure that there is only a single official
representation of it. E.g. ([0..2],[2..4]) is not a valid set, only
([0..4]) is.

By definition, a set is given with its elements, e.g. for any possible
item, you can tell if it is part of the set or not. So if
([0..2],[2..4]) and ([0..4]) have exactly the same elements (by the
given definition), then they are not just equal: they are the same set.
The same reasoning is used in math when they say: there cannot be
multiple empty sets. There exists a single empty set. It happens that we
can only represent a finite number of elements in any set on a computer.
I wanted to have a well defined single way to represent any given set.

I can also see your point. From another point a view, a set and a set of
sets is not the same type. However, I do not share this view, because if
we start thinking this way, then operations like the one below does not
make sense:

[0..4]) - (1..2] == [0..1] | [2..4]

If you make a strinct distinction between intervals and interval sets,
then the above equation does not make sense, because you cannot remove
an element from a set that is not an "element" of it. The above equation
makes sense only if the "intervalset" is a general representation of
possible values, and the "interval" type is a special representation of
(the same) possible values. It is clear when you ask the question: "is 3
in the interval?" and you can also ask "is 3 in the interval set?" - so
the value of the same type can be contained in the interval and also in
the interval set. Maybe the naming is bad, and it should be named
"Intervals" instead of IntervalSet?


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


Import error

2016-04-05 Thread Nicolae Morkov
What can I do   I've tried everything
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Import error

2016-04-05 Thread Tim Golden
On 05/04/2016 10:53, Nicolae Morkov wrote:
> What can I do   I've tried everything
> 

You attached a screenshot, which won't make it through to this text-only
mailing list. Can you copy the actual text of the error message from the
IDLE session and paste it here, please?

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


Re: Import error

2016-04-05 Thread Steven D'Aprano
On Tue, 5 Apr 2016 07:53 pm, Nicolae Morkov wrote:

> What can I do   I've tried everything

You can start by telling us what you are trying to do, and what error you
are getting.

- What module are you trying to import?

- Are you sure it is installed? How do you know?

- What command do you give to import it? COPY and PASTE it, don't 
  type it out from memory.

- What happens? Do you get an error? What EXACT error message do 
  you get? COPY and PASTE the entire error, starting from the
  line "Traceback", don't summarise it or retype it from memory.



Good question, with a useful answer:


Question: I'm trying to import the maths module, so I write `import maths`,
and I get this traceback:

Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named 'maths'

Answer: Try `import math` without the S.



Bad question, with no useful answers:

Question: "It doesn't work! What am I doing wrong"




-- 
Steven

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


Import graphics error

2016-04-05 Thread Nicolae Morkov
# This program creates a graphics window with a rectangle. It provides the
3 # template used with all of the graphical programs used in the book.
4 #
5
6 from graphics import GraphicsWindow
7
8 # Create the window and access the canvas.
9  win = GraphicsWindow()
10 canvas = win.canvas()
11
12 # Draw on the canvas.
13 canvas.drawRect(5, 10, 20, 30)
14
15 # Wait for the user to close the window.
16 win.wait()


*This is the error I get*

Traceback (most recent call last):
  File
"C:/Users/Nicolae/AppData/Local/Programs/Python/Python35/pythonK/pr.py",
line 1, in 
from graphics import GraphicsWindow
ImportError: No module named 'graphics'


*And when I installed graphic library the error was :*

Traceback (most recent call last):
  File
"C:/Users/Nicolae/AppData/Local/Programs/Python/Python35/pythonK/pr.py",
line 1, in 
from graphics import GraphicsWindow
ImportError: cannot import name 'GraphicsWindow'
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Import graphics error

2016-04-05 Thread Steven D'Aprano
On Tue, 5 Apr 2016 08:19 pm, Nicolae Morkov wrote:

> # This program creates a graphics window with a rectangle. It provides the
> 3 # template used with all of the graphical programs used in the book.

What book? 



> *This is the error I get*
> 
> Traceback (most recent call last):
>   File
> "C:/Users/Nicolae/AppData/Local/Programs/Python/Python35/pythonK/pr.py",
> line 1, in 
> from graphics import GraphicsWindow
> ImportError: No module named 'graphics'

Okay. So you didn't have the graphics module installed, and the import
failed because the module wasn't installed.


> *And when I installed graphic library the error was :*
> 
> Traceback (most recent call last):
>   File
> "C:/Users/Nicolae/AppData/Local/Programs/Python/Python35/pythonK/pr.py",
> line 1, in 
> from graphics import GraphicsWindow
> ImportError: cannot import name 'GraphicsWindow'


How did you install it? Are you sure it is the right module?



-- 
Steven

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


Re: Import error

2016-04-05 Thread Tony van der Hoff

On 05/04/16 10:53, Nicolae Morkov wrote:

What can I do   I've tried everything



Just hang your head and cry...

--
Tony van der Hoff| mailto:[email protected]
Buckinghamshire, England |
--
https://mail.python.org/mailman/listinfo/python-list


Can't load Tkinter in embedded Python interpreter on Windows

2016-04-05 Thread Kevin Walzer
I am trying to build a stub exe on Windows that embeds Python and 
launches my Tkinter app. I want a full-blown exe program starter because 
the various Python freezing tools (py2exe, pyinstaller) do not work to 
my satisfaction with Python 3.5.


I am able to get the executable built but I cannot get it to load 
Tkinter and run. The current error is:


"AttributeError: module 'sys' has no attribute 'argv'"

when called from the Tkinter init method.

Here is my command-line invocation for the compiler:

---
gcc quickwho.c -I 
\C:\Users\kevin\AppData\Local\Programs\Python\Python35\include 
-LC:\Users\kevin\AppData\Local\Programs\Python\Python35\libs 
-LC:\Users\kevin\AppData\Local\Programs\Python\Python35\DLLs -lShlwapi 
-lpython35 -o quickwho.exe



And here is my C stub launcher:

#include 


#include 
#include 
#include 
#include 

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

Py_SetProgramName(argv[0]);
Py_Initialize();

 TCHAR exedir [MAX_PATH];


  #if 0
  GetModuleFileName(NULL, exedir, MAX_PATH);
  _tprintf("%s/n", exedir);
  PathRemoveFileSpec(exedir);
  _tprintf("%s/n", exedir);
  #endif

   /*Get the module's full path, and set to the current working 
directory.*/

  if (!GetModuleFileName(NULL, exedir, MAX_PATH)) {

TCHAR errmsg[512];
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0, 
GetLastError(),0,errmsg,1024,NULL);


_tprintf( TEXT("The path is %s, and the error is %s/n"), exedir, 
errmsg );

  }


  if (!PathRemoveFileSpec(exedir)) {

TCHAR errmsg[512];
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0, 
GetLastError(),0,errmsg,1024,NULL);
_tprintf( TEXT("The target dir is %s, and the error is %s/n"), 
exedir, errmsg );

  }

  if (!SetCurrentDirectory(exedir)) {

TCHAR errmsg[512];
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0, 
GetLastError(),0,errmsg,1024,NULL);
_tprintf( TEXT("The working dir is %s, and the error is %s/n"), 
exedir,errmsg );

  }


PyRun_SimpleString("exec(open(\"QuickWho.py\").read())");
Py_Finalize();

return 0;
}

Can anyone suggest what I might do to get Tkinter to load and run my exe?

Thanks,
Kevin

--
Kevin Walzer
Code by Kevin/Mobile Code by Kevin
http://www.codebykevin.com
http://www.wtmobilesoftware.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Promoting Python

2016-04-05 Thread Ben Finney
"Gordon( Hotmail )"  writes:

> I am struggling to understand the basic principles of Python

Welcome! Congratulations for embarking on Python as a language to learn.

Since as you say you are trying to learn the very basics, please
participate in our collaborative tutoring forum
https://mail.python.org/mailman/listinfo/tutor>.

-- 
 \“If one tells the truth, one is sure, sooner or later, to be |
  `\   found out.” —Oscar Wilde, _Phrases and Philosophies for the Use |
_o__)  of the Young_, 1894 |
Ben Finney

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


Re: Promoting Python

2016-04-05 Thread Joel Goldstick
On Tue, Apr 5, 2016 at 3:31 AM, Rustom Mody  wrote:
> On Tuesday, April 5, 2016 at 12:53:13 PM UTC+5:30, Gordon( Hotmail ) wrote:
>> I am struggling to understand the basic principles of Python having spent 
>> many years as a pure Amateur tinkering with a variety of BASIC  as you can 
>> see on my site at http://www.sigord.co.uk/  I think you will agree all such 
>> versions of Basic I have used are far easier to understand than Python. 
>> Though with my limited knowledge I accept Python may have many advantages 
>> over say Liberty Basic etc.
>>
>> The problem I am finding is most of the sites claiming to help understand 
>> Python devote far too much space bragging about the wonders of Python 
>> instead of concentrating how to make sensible use of it. For example I 
>> struggle to find examples of such as below if you could please help me. If I 
>> manage to duplicate some of my efforts on my site with Python I will be 
>> happy to upload the code to my site. I will also try to upload working exec 
>> files of such also, except my previous attempts at downloading the relevant 
>> software was blocked by AVG software as risky.
>>
>> Gordon
>>
>>
>> Liberty Basic
>> for n = 32 to 255: print n;chr$(n) : next n
>
> I grew up on BBC basic in 1984. Not used thereafter.
>
> Your first one is (I guess) this in python:
>
 for i in range(32,127):
> ...   print chr(i),
> ...
>   ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F 
> G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m 
> n o p q r s t u v w x y z { | } ~
>
>>
>> REM BBC Basic
>> FOR c = 1 TO 15 : COLOUR c
>>   PRINT "Color ";c
>> NEXT c
>>
>> REM BBC Basic
>> c = 0
>> FOR x = 80 TO 2000 STEP 96
>>   GCOL c: CIRCLE FILL x,500,50 : c = c + 1
>> NEXT x
>
> If you tell us some more of what color, gcol etc do someone will likely show 
> you
> Though in all fairness I dont expect it to be as pithy as the BASIC
> --
> https://mail.python.org/mailman/listinfo/python-list

The color stuff has to do with DOS based 16 color displays I think.
Or maybe it worked with other 16 color displays of the time

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Promoting Python

2016-04-05 Thread Joaquin Alzola

>"Gordon( Hotmail )"  writes:

>> I am struggling to understand the basic principles of Python

>Welcome! Congratulations for embarking on Python as a language to learn.

>Since as you say you are trying to learn the very basics, please participate 
>in our collaborative tutoring forum 
>https://mail.python.org/mailman/listinfo/tutor>.

Python is like shell scripting but with Steroids. For a SysAdmin is a must.
This email is confidential and may be subject to privilege. If you are not the 
intended recipient, please do not copy or disclose its content but contact the 
sender immediately upon receipt.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Promoting Python

2016-04-05 Thread Marko Rauhamaa
Dennis Lee Bieber :
>   For the OP: Very few languages have built-in graphics commands;
> which is why porting BASIC programs was so difficult. This means you
> have to import some graphical framework and use ITS command functions.

The Racket dialect of the Scheme programming language has an interesting
approach:

   | > (circle 10)
   | ⚪

   [...]

   | > (rectangle 10 20)
   | ▯


   [...]

   | > (hc-append (circle 10) (rectangle 10 20))
   | ⚪▯

   https://docs.racket-lang.org/quick/>

Follow the link for more elaborate examples.


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


Re: Promoting Python

2016-04-05 Thread Marko Rauhamaa
Joaquin Alzola :

> Python is like shell scripting but with Steroids. For a SysAdmin is a must.
> This email is confidential and may be subject to privilege. If you are
> not the intended recipient, please do not copy or disclose its content
> but contact the sender immediately upon receipt.

Oh, I didn't notice the end of the paragraph at first and ended up
reading the beginning.

If I wasn't the intended recipient, I apologize. I recommend you to
encrypt your future messages with rot-13 to make sure such breaches of
confidentiality won't be inadvertently repeated.


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


Re: Promoting Python

2016-04-05 Thread Peter Otten
Gordon( Hotmail ) wrote:

Welcome!

> I am struggling to understand the basic principles of Python having spent
> many years as a pure Amateur tinkering with a variety of BASIC  as you can
> see on my site at http://www.sigord.co.uk/  I think you will agree all
> such versions of Basic I have used are far easier to understand than
> Python. 

I don't think it is Python versus Basic; older computers had simpler 
hardware and ran simpler software. Try to find your way around in the 
variant of Basic used by Microsoft's Word or Excel to see what I mean. You 
can show a dialog to fill in a form, but you may also be able to instrument 
a hostile takover of the machine of someone who opens your "document".

Python still allows you to write simple scripts that read a text file line 
by line, do something with the contents, and print the results in a terminal 
window or write them to another file. 

It also has libraries for almost everything you can imagine, too many to 
know all of them. The first thing you do when you try something new is to 
look for a library that may help. What are your options? Is there a de-facto 
standard? Is there something more advanced that promises to reduce the 
amount of code you'll have to write? Is there even a complete application 
ready to use?

> Though with my limited knowledge I accept Python may have many
> advantages over say Liberty Basic etc.
> 
> The problem I am finding is most of the sites claiming to help understand
> Python devote far too much space bragging about the wonders of Python
> instead of concentrating how to make sensible use of it. For example I
> struggle to find examples of such as below if you could please help me. 

> Liberty Basic
> for n = 32 to 255: print n;chr$(n) : next n

This is pretty much what it used to be:


for i in range(32, 256):
print(i, chr(i))

The main gotcha is that Python uses half-open intervals (i. e. range(32, 
256) does include 32 but not 256).


> REM BBC Basic
> FOR c = 1 TO 15 : COLOUR c
>   PRINT "Color ";c
> NEXT c

You may find that easy to understand, but what is 

COLOUR 7

? Without the Basic manual you have no way of knowing.

Here's a simple way to print colored text in Python:

from termcolor import cprint
for color in ["grey", "red", "green", "yellow", "blue", "magenta", "cyan"]:
cprint("Colour:", color)
cprint("Colour: white", "white", "on_red")

Here the hard part is finding the library that best fits your need.  
"termcolor" which I used is not part of Python's standard library, you have 
to download it from the Python Package Index (or install it from the 
repositories of your distribution if you are a Linux user).

> REM BBC Basic
> c = 0
> FOR x = 80 TO 2000 STEP 96
>   GCOL c: CIRCLE FILL x,500,50 : c = c + 1
> NEXT x

This is again harder. You don't get direct access to the screen; you have to 
pick a toolkit that is typically a library written in C or C++ with a thin 
Python wrapper. The C/C++ languages tend to offer interfaces that require a 
lot of bookkeeping, and some of this makes it into the Python interface. 

Another source of complexity is that these toolkits' main purpose is not 
drawing shapes on the screen.

In tkinter, for example, which is part of the standard library and wraps 
code written in TCL and C, you have to create a Window (called "Toplevel") 
and put a "Canvas" widget into it:

import tkinter as tk

root = tk.Tk()
canvas = tk.Canvas(root, width=500, height=300)
canvas.pack()

def circle(x, y, radius, fillcolor=None):
"""Draw a circle of `radius` around the center (`x`, `y`)."""
canvas.create_oval(x-radius, y-radius, x+radius, y+radius, 
fill=fillcolor)

RADIUS = 25
x = 80
for fillcolor in ["navy", None, "silver", "maroon", "white"]:
circle(x, 150, RADIUS, fillcolor)
x += 80 # draw next circle 80 pixels to the right
root.mainloop()

I iterated over the colors instead of the positions; I also wrote a helper 
function to allow you to specify the circles by their center and radius 
instead of the bounding box.

For beginners or children there is also the "turtle" module, a port of a 
library initially written in Logo.


> If
> I manage to duplicate some of my efforts on my site with Python I will be
> happy to upload the code to my site. I will also try to upload working
> exec files of such also, except my previous attempts at downloading the
> relevant software was blocked by AVG software as risky.

Before you really get frustrated you might consider using a cheap spare 
computer with a Linux installation for your experiments. If you don't hoard 
old machines in your basement the raspberry pi and the raspbian distribution 
nicely fit that bill ;)

> I am struggling to understand the basic principles of Python having spent

A good place to find help while making your first steps is the tutor mailing 
list.

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


Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-05 Thread Random832
On Tue, Apr 5, 2016, at 01:44, Nagy László Zsolt wrote:
> If you want to manipulate an interval set, you cannot just "add another
> interval" to it. Adding an interval may result in unifying thousands of
> other intervals. It is possible that you add a wide interval to a set
> with 1000 elements, and as a result the set will have only a single
> element.

Yeah, but it's not clear why the add method can't do the same
unification that the constructor does.

> How about creating two classes for this? One that supports zero sized
> intervals, and another that doesn't?

If you don't want zero sized intervals, just don't put any in it. You
don't have a separate list type to support even integers vs one that
supports all floats. What operations are made different in
implementation by this restriction?

> Well, here is the problem: floats, ints, decimals and datetimes are all
> ordered types. But they all have a different resolution, and some of
> them are implementation dependent.

All real number types should be considered a single type for the purpose
of implementing something like this. There's no reason you shouldn't be
able to mix floats, ints, Decimals, and Fractions (the last of which has
conceptually infinite resolution).

> We must know and use the smallest
> resolution, even if we use boolean flags to denote openness. For
> example: if we use integer values, then the closed interval [1,9] is
> equal to the open interval (0,10) or the left-open interval (0,10]. We
> want to be able to compare them, so we must know the resolution!

There's no reason to consider (0, 10) equal to _any_ closed interval.

> If we
> stay at the generalized form of the class that can be used on any
> ordered type, then we cannot avoid using the concept of the "resolution
> of the type". Here are the choices:
> 
>   * Use boolean flags to denote openness:
>   o We do not support testing for interval equality - I think that
> missing this fundamental operator would make the implementation
> useless.

I don't see how considering some intervals to not be equal to others
means not supporting testing interval equality.

>   o Support testing for internal equality - this requires knowledge
> about the smallest resolution, so in this case using flags to
> denote openness makes it possible to represent the same interval
> in 4 different ways! (left opened/closed, right opened/closed).
> I think this is also a bad idea.
>   o We may have an agreement about how we should represent certain
> intervals from the 4 different possible opportunities, but the
> simplest way would be to always store them as closed intervals -
> which makes these boolean flags unneccessary
>   * Do not use boolean flags to denote openness - I don't see any
> problem here.
> 
> 
> I think the problem is that you are thinking the mathematical way, where
> an open interval can never be equal to a closed interval. I was thinking
> the IT way, where everything is represented with bits, and the "open
> interval" is just a concept that always has a biggest and a smallest
> possible value.

The smallest possible value of a Fraction above zero is limited only by
available memory (its denominator is the largest possible int). You
could also reasonably implement a "higher-resolution datetime class"
which can be interchangeably and compared with normal datetimes... maybe
even with a Fraction for fractional seconds.

> Well, I have also implemented __gt__ but its interpretation is equally
> blurry. When two intervals overlap, which is the bigger?

With set types, the comparison operations are is-subset-of operations,
i.e. a < b returns true if a is _completely contained within_ b, and
false if they do not intersect or they overlap differently on both
sides. It does not imply that all values in a are less than all values
in b (that would be a different operation)

> My original
> task was to compare working hours (intervals) of employees and in that
> interpretation, the above "contains" operation was useful.

Of course the operation is useful. My entire point is that it should be
spelled "a < b" not "a in b".

Look at sets to see what I'm talking about:

{1, 2} < {1, 2, 3}: True
{2, 3} < {1, 2, 3}: True
{1, 3} < {1, 2, 3}: True

{1, 2} < {2, 3}: False
{1, 2} > {2, 3}: False

{1, 2} < {1, 2}: False
{1, 2} <= {1, 2}: True
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Untrusted code execution

2016-04-05 Thread Jon Ribbens
On 2016-04-03, Jon Ribbens  wrote:
> I'd just like to say up front that this is more of a thought experiment
> than anything else, I don't have any plans to use this idea on any
> genuinely untrusted code. Apart from anything else, there's the
> denial-of-service issue.
>
> That said, is there any way that the following Python 3.4 code could
> result in a arbitrary code execution security hole?
>
> tree = compile(untrusted_code, "

Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-05 Thread Random832
On Tue, Apr 5, 2016, at 04:11, Nagy László Zsolt wrote:
>  But there is still need to check begin <= end. But maybe
> you are right: if we suppose that nobody will try to use an interval
> where end < begin then we can use plain tuples. But then the user *must*
> make sure not to use invalid intervals.

The IntervalSet constructor and add method could switch them or throw an
exception. But I'm not saying to use plain tuples. I'm saying to make
Interval a "dumb" object, which *only* supports being constructed and
added to a set, rather than putting a bunch of set-like operations on
it.

> It is blurred by design. There is an interpretation where an interval
> between [0..4] equals to a set of intervals ([0..2],[2..4]).

No, because 2.5 is in one and not the other. Floats are orderable with
ints, so it's not reasonable to say "this is an int intervalset so no
floats are contained in it". But that's another discussion.

But why would you want to use [0..4] directly instead of ([0..4])?

> Actually,
> you can ask: "is an element within the interval?" The same question can
> be asked for an Interval set. So the same type of value can be
> "contained" within an interval and also witin an interval set. In the
> current implementation, if you try to create a set with these two
> intervals [0..2] and [2..4], then they are unified into a single element
> on purpose: to make sure that there is only a single official
> representation of it. E.g. ([0..2],[2..4]) is not a valid set, only
> ([0..4]) is.

Uh, exactly. I don't understand why any of this makes it useful to have
these operations on interval objects.

> By definition, a set is given with its elements, e.g. for any possible
> item, you can tell if it is part of the set or not. So if
> ([0..2],[2..4]) and ([0..4]) have exactly the same elements (by the
> given definition), then they are not just equal: they are the same set.
> The same reasoning is used in math when they say: there cannot be
> multiple empty sets. There exists a single empty set. It happens that we
> can only represent a finite number of elements in any set on a computer.
> I wanted to have a well defined single way to represent any given set.

What? *I* am the one who wants a well defined single way to represent a
given set. *You* are the one who wants to make [0..4] a set-like object
that is different from ([0..4]) and doesn't quite support the same
operations.

> I can also see your point. From another point a view, a set and a set of
> sets is not the same type.

I'm saying an interval is _not_ a set. It is merely part of the way of
describing the set. Just like the word "of" isn't a set just because
"the set of all even numbers" is a set.

You could consider "the set of [dates|numbers|etc] in a single interval"
to be a type of set, certainly. But there's no reason to have such a set
_not_ fully support set operations even when those operations will not
return a set of a single interval.

> However, I do not share this view, because if
> we start thinking this way, then operations like the one below does not
> make sense:
> 
> [0..4]) - (1..2] == [0..1] | [2..4]
> 
> If you make a strinct distinction between intervals and interval sets,
> then the above equation does not make sense, because you cannot remove
> an element from a set that is not an "element" of it. The above equation
> makes sense only if the "intervalset" is a general representation of
> possible values, and the "interval" type is a special representation of
> (the same) possible values.

I don't understand why you want to let the user use the "interval" type
for purposes other than adding to an intervalset in the first place
Nothing you've posted has explained this.

> It is clear when you ask the question: "is 3
> in the interval?" and you can also ask "is 3 in the interval set?"
> - so
> the value of the same type can be contained in the interval and also in
> the interval set. Maybe the naming is bad, and it should be named
> "Intervals" instead of IntervalSet?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Untrusted code execution

2016-04-05 Thread Rustom Mody
On Tuesday, April 5, 2016 at 7:19:39 PM UTC+5:30, Jon Ribbens wrote:
> On 2016-04-03, Jon Ribbens wrote:
> > I'd just like to say up front that this is more of a thought experiment
> > than anything else, I don't have any plans to use this idea on any
> > genuinely untrusted code. Apart from anything else, there's the
> > denial-of-service issue.
> >
> > That said, is there any way that the following Python 3.4 code could
> > result in a arbitrary code execution security hole?
> >
> > tree = compile(untrusted_code, "

Re: Untrusted code execution

2016-04-05 Thread Ian Kelly
On Tue, Apr 5, 2016 at 8:17 AM, Rustom Mody  wrote:
> On Tuesday, April 5, 2016 at 7:19:39 PM UTC+5:30, Jon Ribbens wrote:
>> On 2016-04-03, Jon Ribbens wrote:
>> > I'd just like to say up front that this is more of a thought experiment
>> > than anything else, I don't have any plans to use this idea on any
>> > genuinely untrusted code. Apart from anything else, there's the
>> > denial-of-service issue.
>> >
>> > That said, is there any way that the following Python 3.4 code could
>> > result in a arbitrary code execution security hole?
>> >
>> > tree = compile(untrusted_code, "

Re: ONE CLICK REST API

2016-04-05 Thread Roland Mueller via Python-list
You may have a look at Django-based REST framework

   - http://www.django-rest-framework.org/

or Flask-RESTful

   - https://pypi.python.org/pypi/Flask-RESTful
   - http://flask-restful-cn.readthedocs.org/en/0.3.4/

Last not least here is some article about implementing a REST API using
Flask for yourself:

   -
   
http://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask


BR,
Roland

2016-04-04 9:09 GMT+03:00 David Shi via Python-list 
:

> Eclipse has got one click app for creating REST services.
> What is it equivalent in Python?
> Regards.
> David
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Label behavior's difference between tkinter and ttk

2016-04-05 Thread Mark Lawrence via Python-list

On 05/04/2016 07:57, ast wrote:

Hello

I currently migrate a GUI from tkinter to ttk and I found a problem

Here is a piece of code, with comments which explain what is wrong.

import tkinter as tk
import tkinter.ttk as ttk

root = tk.Tk()

BITMAP0 = """
#define zero_width 24
#define zero_height 32
static char zero_bits[] = {
0x00,0x00,0x00, 0x00,0x00,0x00, 0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f,
0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00,
0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f,
0x00,0x00,0x00, 0x00,0x00,0x00, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f,
0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00,
0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f,
0x00,0x00,0x00, 0x00,0x00,0x00, 0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f,
0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00
};
"""

img = tk.BitmapImage(data=BITMAP0, foreground='white', background='black')

# This Label comes from ttk

label = ttk.Label(root, image=img)

# This Label comes from tk. To be uncommented to test behavior'difference
# label = tk.Label(root, image=img)

label.pack()

# The graphic is not refreshed after entering following commands
# when Label comes from ttk. You have to fly over the label with # the
mouse to get the right color.
# The graphic is immediately updated when Label comes from tk

# Enter these commands by hand, in a shell

img.config(foreground='red')
img.config(foreground='lime')
img.config(foreground='yellow')


It looks like a ttk bug, isn't it ?
I am using python 3.5.1

I tried a root.update_idletasks() to refresh the graphic
but it changed nothings.



I'm no tkinter expert, but I do know that there is a huge difference 
between the way that tk and ttk widgets are configured.  Here are a few 
links that I hope will give you an idea.


http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-Label.html
http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-layouts.html
http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-map.html
http://www.tkdocs.com/tutorial/styles.html

In the latter you might like to note that there is a section called 
"Sound Difficult to you?".  It's well worth the read.


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

Mark Lawrence

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


Re: tkinter Entry validation modes

2016-04-05 Thread Mark Lawrence via Python-list

On 02/04/2016 19:45, Terry Reedy wrote:

On 4/2/2016 11:11 AM, Mark Lawrence via Python-list wrote:

A typical call to create an Entry field would be:-

e = Entry(master, validate='all', ...)

Once this call has been made is it possible to change the validation
mode at runtime?


AFAIK, every keyword-only configuration option can be changed.

e['validate'] = xyz
e.config(validate=xyz)



Yes, there's an write up on it here 
http://effbot.org/tkinterbook/tkinter-widget-configuration.htm


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

Mark Lawrence

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


python script for .dat file

2016-04-05 Thread Muhammad Ali

Hello,

Could any body tell me a general python script to generate .dat file after the 
extraction of data from more than 2 files, say file A and file B?

Or could any body tell me the python commands to generate .dat file after the 
extraction of data from two or more than two files?

I have to modify some python code.

Looking for your valuable posts.

Thank you.

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


Re: python script for .dat file

2016-04-05 Thread Joel Goldstick
On Tue, Apr 5, 2016 at 11:23 AM, Muhammad Ali
 wrote:
>
> Hello,
>
> Could any body tell me a general python script to generate .dat file after 
> the extraction of data from more than 2 files, say file A and file B?
>
> Or could any body tell me the python commands to generate .dat file after the 
> extraction of data from two or more than two files?
>
> I have to modify some python code.
>
> Looking for your valuable posts.
>
> Thank you.
>
> Ali
> --
> https://mail.python.org/mailman/listinfo/python-list

What exactly is a .dat file? and how is it different from any other
file? Is it binary or text data?


-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python script for .dat file

2016-04-05 Thread Muhammad Ali
On Tuesday, April 5, 2016 at 8:30:27 AM UTC-7, Joel Goldstick wrote:
> On Tue, Apr 5, 2016 at 11:23 AM, Muhammad Ali
>  wrote:
> >
> > Hello,
> >
> > Could any body tell me a general python script to generate .dat file after 
> > the extraction of data from more than 2 files, say file A and file B?
> >
> > Or could any body tell me the python commands to generate .dat file after 
> > the extraction of data from two or more than two files?
> >
> > I have to modify some python code.
> >
> > Looking for your valuable posts.
> >
> > Thank you.
> >
> > Ali
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> 
> What exactly is a .dat file? and how is it different from any other
> file? Is it binary or text data?
> 
> 
> -- 
> Joel Goldstick
> http://joelgoldstick.com/blog
> http://cc-baseballstats.info/stats/birthdays

It is text data.
-- 
https://mail.python.org/mailman/listinfo/python-list


Install request

2016-04-05 Thread Igor Korot
 Hi, python community,
Recently there was a huge number of e-mail stating that the python
installer does not work.

When asked about it, people reveal that they wee using Windows and
they were getting
errors about missing DLL.

I know for a fact that in the InstallShield it is possible to detect
the OS you are trying
to install on.

So, here is my request: if its not possible to include the DLL in
question in the installer,
can the installer check for the OS version and ask the user to go to
Microsoft.com,
download and install the library?

It looks like people don't want to use their common sense and just
wanted to waste
everybody's time by asking what went wrong instead of just download
the dll executable
from MS site and install it.

Can something like this be done to eliminate those questions in the
future and let people
concentrate on the real python issues?

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


Re: python script for .dat file

2016-04-05 Thread Mark Lawrence via Python-list

On 05/04/2016 16:23, Muhammad Ali wrote:


Hello,

Could any body tell me a general python script to generate .dat file after the 
extraction of data from more than 2 files, say file A and file B?

Or could any body tell me the python commands to generate .dat file after the 
extraction of data from two or more than two files?

I have to modify some python code.

Looking for your valuable posts.

Thank you.

Ali



https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files

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

Mark Lawrence

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


Re: python script for .dat file

2016-04-05 Thread Oscar Benjamin
On 5 April 2016 at 16:44, Muhammad Ali  wrote:
> On Tuesday, April 5, 2016 at 8:30:27 AM UTC-7, Joel Goldstick wrote:
>> On Tue, Apr 5, 2016 at 11:23 AM, Muhammad Ali
>>  wrote:
>> >
>> > Could any body tell me a general python script to generate .dat file after 
>> > the extraction of data from more than 2 files, say file A and file B?
>> >
>> > Or could any body tell me the python commands to generate .dat file after 
>> > the extraction of data from two or more than two files?
>> >
>> > I have to modify some python code.
>>
>> What exactly is a .dat file? and how is it different from any other
>> file? Is it binary or text data?
>
> It is text data.

You haven't provided enough information for someone to answer your
question. This is a text mailing list so if a .dat file is text then
you can paste here an example of what it would look like. What would
be in your input files and what would be in your output files? What
code have you already written?

If the file is large then don't paste its entire content here. Just
show an example of what the data would look like if it were a smaller
file (maybe just show the first few lines of the file).

Probably what you want to do is easily achieved with basic Python
commands so I would recommend to have a look at a tutorial. There are
some listed here:
https://wiki.python.org/moin/BeginnersGuide/NonProgrammers

Also the tutor mailing list is probably more appropriate for this
level of question:
https://mail.python.org/mailman/listinfo/tutor

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


Re: Install request

2016-04-05 Thread Oscar Benjamin
On 5 April 2016 at 16:56, Igor Korot  wrote:
>
> So, here is my request: if its not possible to include the DLL in
> question in the installer,
> can the installer check for the OS version and ask the user to go to
> Microsoft.com,
> download and install the library?

That's a very reasonable request. Why don't you ask this question on
the issue tracker? You can find it here:

http://bugs.python.org/

> It looks like people don't want to use their common sense and just
> wanted to waste
> everybody's time by asking what went wrong instead of just download
> the dll executable
> from MS site and install it.

I think these questions are coming from people who are completely new
to Python (and programming in general) so they find the error message
confusing and are unsure if they're doing something wrong or if the
installer hasn't worked or whatever. If you see this problem when
trying to run Python for the first time then it's hardly obvious that
you need to "update your runtime libraries".

There seem to be several different problems that Windows users are
experiencing with 3.5 and this one is the only one that actually has a
known fix: the others probably are bugs in the installer. I don't
think it's unreasonable for people to come here and ask about this. In
particular this is listed as the main place to "ask for help" on the
wiki:
https://wiki.python.org/moin/Asking%20for%20Help

Another possibility to improve this situation would be to make a page
on the wiki that actually explains the known problems (and fixes) for
3.5 on Windows.

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


Re: Import graphics error

2016-04-05 Thread Nicolae Morkov
I copied the code from Python from everyone page 67.
Following the instructions The graphic modules by John Zelle I copied  into
the python lacation ,to be easier to find the path .


On Tue, Apr 5, 2016 at 11:19 AM, Nicolae Morkov 
wrote:

> # This program creates a graphics window with a rectangle. It provides the
> 3 # template used with all of the graphical programs used in the book.
> 4 #
> 5
> 6 from graphics import GraphicsWindow
> 7
> 8 # Create the window and access the canvas.
> 9  win = GraphicsWindow()
> 10 canvas = win.canvas()
> 11
> 12 # Draw on the canvas.
> 13 canvas.drawRect(5, 10, 20, 30)
> 14
> 15 # Wait for the user to close the window.
> 16 win.wait()
>
>
> *This is the error I get*
>
> Traceback (most recent call last):
>   File
> "C:/Users/Nicolae/AppData/Local/Programs/Python/Python35/pythonK/pr.py",
> line 1, in 
> from graphics import GraphicsWindow
> ImportError: No module named 'graphics'
>
>
> *And when I installed graphic library the error was :*
>
> Traceback (most recent call last):
>   File
> "C:/Users/Nicolae/AppData/Local/Programs/Python/Python35/pythonK/pr.py",
> line 1, in 
> from graphics import GraphicsWindow
> ImportError: cannot import name 'GraphicsWindow'
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Import graphics error

2016-04-05 Thread Nicolae Morkov
*Import graphics error*
I copied the code below from Python for Everyone page 67.

# This program creates a graphics window with a rectangle. It provides the
3 # template used with all of the graphical programs used in the book.
4 #
5
6 from graphics import GraphicsWindow
7
8 # Create the window and access the canvas.
9 win = GraphicsWindow()
10 canvas = win.canvas()
11
12 # Draw on the canvas.
13 canvas.drawRect(5, 10, 20, 30)
14
15 # Wait for the user to close the window.
16 win.wait()


**This is the error I get* *

Traceback (most recent call last):
File
"C:/Users/Nicolae/AppData/Local/Programs/Python/Python35/pythonK/pr.py",
line 1, in 
from graphics import GraphicsWindow
ImportError: No module named 'graphics'


*Following the instructions I copied The graphic modules by John Zelle in
Python folder in Lib folder *
**And when I installed graphic library the error was :* *

Traceback (most recent call last):
File
"C:/Users/Nicolae/AppData/Local/Programs/Python/Python35/pythonK/pr.py",
line 1, in 
from graphics import GraphicsWindow
ImportError: cannot import name 'GraphicsWindow'
-- 
https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python script for .dat file

2016-04-05 Thread Muhammad Ali
On Tuesday, April 5, 2016 at 9:07:54 AM UTC-7, Oscar Benjamin wrote:
> On 5 April 2016 at 16:44, Muhammad Ali  wrote:
> > On Tuesday, April 5, 2016 at 8:30:27 AM UTC-7, Joel Goldstick wrote:
> >> On Tue, Apr 5, 2016 at 11:23 AM, Muhammad Ali
> >>  wrote:
> >> >
> >> > Could any body tell me a general python script to generate .dat file 
> >> > after the extraction of data from more than 2 files, say file A and file 
> >> > B?
> >> >
> >> > Or could any body tell me the python commands to generate .dat file 
> >> > after the extraction of data from two or more than two files?
> >> >
> >> > I have to modify some python code.
> >>
> >> What exactly is a .dat file? and how is it different from any other
> >> file? Is it binary or text data?
> >
> > It is text data.
> 
> You haven't provided enough information for someone to answer your
> question. This is a text mailing list so if a .dat file is text then
> you can paste here an example of what it would look like. What would
> be in your input files and what would be in your output files? What
> code have you already written?
> 
> If the file is large then don't paste its entire content here. Just
> show an example of what the data would look like if it were a smaller
> file (maybe just show the first few lines of the file).
> 
> Probably what you want to do is easily achieved with basic Python
> commands so I would recommend to have a look at a tutorial. There are
> some listed here:
> https://wiki.python.org/moin/BeginnersGuide/NonProgrammers
> 
> Also the tutor mailing list is probably more appropriate for this
> level of question:
> https://mail.python.org/mailman/listinfo/tutor
> 
> --
> Oscar

Input and outout files are text files. e.g: 
#KptCoord #E-E_Fermi #delta_N
  0.  -22.   0.000E+00
  0.0707  -22.   0.000E+00
  0.1415  -22.   0.000E+00
  0.2122  -22.   0.000E+00
  0.2830  -22.   0.000E+00
  0.3537  -22.   0.000E+00
  0.4245  -22.   0.000E+00
  0.4952  -22.   0.000E+00
  0.5660  -22.   0.000E+00
  0.6367  -22.   0.000E+00
  0.7075  -22.   0.000E+00
  0.7782  -22.   0.000E+00
  0.8490  -22.   0.000E+00
  0.9197  -22.   0.000E+00
  0.9905  -22.   0.000E+00
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Install request

2016-04-05 Thread Rustom Mody
On Tuesday, April 5, 2016 at 9:49:58 PM UTC+5:30, Oscar Benjamin wrote:
> Another possibility to improve this situation would be to make a page
> on the wiki that actually explains the known problems (and fixes) for
> 3.5 on Windows.

+10 on that one
ie When a question becomes a FAQ just put it there
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Untrusted code execution

2016-04-05 Thread Chris Angelico
On Wed, Apr 6, 2016 at 12:50 AM, Ian Kelly  wrote:
> Same here, although it looks to me like this approach could work. Or
> I'm just not clever enough to see how it could be exploited.

Having been bitten in the past (our test box was compromised by
python-list white hats within 20 minutes of the invitation being sent
out), I would go with the second of your options. Nearly anything is
vulnerable if it's permitted to execute arbitrary code; all it takes
is a sufficiently smart operator.

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


Re: Untrusted code execution

2016-04-05 Thread Jon Ribbens
On 2016-04-05, Rustom Mody  wrote:
> On Tuesday, April 5, 2016 at 7:19:39 PM UTC+5:30, Jon Ribbens wrote:
>> On 2016-04-03, Jon Ribbens wrote:
>> > I'd just like to say up front that this is more of a thought experiment
>> > than anything else, I don't have any plans to use this idea on any
>> > genuinely untrusted code. Apart from anything else, there's the
>> > denial-of-service issue.
>> >
>> > That said, is there any way that the following Python 3.4 code could
>> > result in a arbitrary code execution security hole?
>> >
>> > tree = compile(untrusted_code, "

Re: Best Practices for Internal Package Structure

2016-04-05 Thread Sven R. Kunze

On 05.04.2016 03:43, Steven D'Aprano wrote:

The purpose of packages isn't enable Java-style "one class per file" coding,
especially since *everything* in the package except the top level "bidict"
module itself is private. bidict.compat and bidict.util aren't flagged as
private, but they should be, since there's nothing in either of them that
the user of a bidict class should care about.

(utils.py does export a couple of functions, but they should be in the main
module, or possibly made into a method of BidirectionalMapping.)

Your package is currently under 500 lines. As it stands now, you could
easily flatten it to a single module:

bidict.py


I don't recommend this.

The line is blurry but 500 is definitely too much. Those will simply not 
fit on a 1 or 2 generous single screens anymore (which basically is our 
guideline). The intention here is to always have a bit more of a full 
screen of code (no wasted pixels) while benefiting from switching to 
another file (also seeing a full page of other code).


This said, and after having a look at your packages code, it's quite 
well structured and you have almost always more than 1 name defined in 
each submodule. So, it's fine. _frozen and _loose are a bit empty but 
well don't let's stretch rules here too far.


I remember us having some years ago file that regularly hit the 3000 or 
4000 lines of code. We systematically split those up, refactored them 
and took our time to name those module appropriately. Basically we 
started with:


base.py << trashcan for whatever somebody might need

to

base.py << really the base
domain_specific1.py  << something you can remember
domain_specific2.py  << ...
domain_specific3.py
domain_specific4.py



Unless you are getting some concrete benefit from a package structure, you
shouldn't use a package just for the sake of it.


I agree.


Even if the code doubles
in size, to 1000 lines, that's still *far* below the point at which I
believe a single module becomes unwieldy just from size. At nearly 6500
lines, the decimal.py module is, in my opinion, *almost* at the point where
just size alone suggests splitting the file into submodules. Your module is
nowhere near that point.


I disagree completely. After reading his package, the structure really 
helped me. So, I see a benefit.



I agree with Steven that hiding where a name comes from is a bit 
problematic. Additionally, as we use PyCharm internally, 1) we don't see 
imports regularly 2) we don't create/optimize them manually anymore 3) 
we just don't care if the import is too long. So, it's fine to us and as 
PyCharm tried not to be overly clever when it comes to detecting names, 
we like the direct way.


In case of our PyPI module, usability is really important for newbies 
and people not using sophisticated IDEs. So, making it really easy for 
them is a must. :)


Best,
Sven
--
https://mail.python.org/mailman/listinfo/python-list


Re: Untrusted code execution

2016-04-05 Thread Jon Ribbens
On 2016-04-05, Chris Angelico  wrote:
> On Wed, Apr 6, 2016 at 12:50 AM, Ian Kelly  wrote:
>> Same here, although it looks to me like this approach could work. Or
>> I'm just not clever enough to see how it could be exploited.
>
> Having been bitten in the past (our test box was compromised by
> python-list white hats within 20 minutes of the invitation being sent
> out), I would go with the second of your options. Nearly anything is
> vulnerable if it's permitted to execute arbitrary code; all it takes
> is a sufficiently smart operator.

I am inviting sufficiently smart operators to demonstrate the flaw in
my suggested code ;-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Untrusted code execution

2016-04-05 Thread Chris Angelico
On Wed, Apr 6, 2016 at 3:26 AM, Jon Ribbens
 wrote:
> The received wisdom is that restricted code execution in Python is
> an insolubly hard problem, but it looks a bit like my 7-line example
> above disproves this theory, provided you choose carefully what you
> provide in your restricted __builtins__ - but people who knows more
> than me about Python seem to have thought about this problem for
> longer than I have and come up with the opposite conclusion so I'm
> curious what I'm missing.

No, it doesn't disprove anything. All you've shown is "here's a piece
of code that hasn't yet been compromised". :) What you're missing is a
demonstrated exploit against your code. I can't provide one, but it's
entirely possible that one will be found.

Your code is a *lot* safer for using 'eval' rather than 'exec'.
Otherwise, you'd be easily exploited using exceptions, which carry a
ton of info. But even so, I would not bet money (much less the
security of my systems) on this being safe.

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


Re: Untrusted code execution

2016-04-05 Thread Ian Kelly
On Tue, Apr 5, 2016 at 11:48 AM, Chris Angelico  wrote:
> Your code is a *lot* safer for using 'eval' rather than 'exec'.
> Otherwise, you'd be easily exploited using exceptions, which carry a
> ton of info. But even so, I would not bet money (much less the
> security of my systems) on this being safe.

Not to mention "import". :-P
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best Practices for Internal Package Structure

2016-04-05 Thread Chris Angelico
On Wed, Apr 6, 2016 at 3:38 AM, Sven R. Kunze  wrote:
>> Your package is currently under 500 lines. As it stands now, you could
>> easily flatten it to a single module:
>>
>> bidict.py
>
>
> I don't recommend this.
>
> The line is blurry but 500 is definitely too much. Those will simply not fit
> on a 1 or 2 generous single screens anymore (which basically is our
> guideline). The intention here is to always have a bit more of a full screen
> of code (no wasted pixels) while benefiting from switching to another file
> (also seeing a full page of other code).

Clearly this is a matter of opinion. I have absolutely no problem with
a 500-lne file. As soon as you force people to split things across
files, you add a new level of indirection that causes new problems.
I'd rather keep logically-related code together rather than splitting
across arbitrary boundaries; you can always search within a file for
the bit you want. When you split a file into two, you duplicate the
headers at the top (imports and stuff), so you'll split a 100-line
file into two 60-line files or so. Do that to several levels in a big
project and you end up with a lot more billable lines of code, but no
actual improvement. I guess that's worth doing - lovely billable hours
doing the refactoring, more billable hours later on when you have to
read past the migration in source control ("where did this line come
from" gets two answers all the time), and more billable hours dealing
with circular imports when two fragments start referring to each
other. Sounds like a plan.

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


Re: Promoting Python

2016-04-05 Thread alister
On Tue, 05 Apr 2016 08:06:02 -0400, Joel Goldstick wrote:

> On Tue, Apr 5, 2016 at 3:31 AM, Rustom Mody 
> wrote:
>> On Tuesday, April 5, 2016 at 12:53:13 PM UTC+5:30, Gordon( Hotmail )
>> wrote:
>>> I am struggling to understand the basic principles of Python having
>>> spent many years as a pure Amateur tinkering with a variety of BASIC 
>>> as you can see on my site at http://www.sigord.co.uk/  I think you
>>> will agree all such versions of Basic I have used are far easier to
>>> understand than Python. Though with my limited knowledge I accept
>>> Python may have many advantages over say Liberty Basic etc.
>>>
>>> The problem I am finding is most of the sites claiming to help
>>> understand Python devote far too much space bragging about the wonders
>>> of Python instead of concentrating how to make sensible use of it. For
>>> example I struggle to find examples of such as below if you could
>>> please help me. If I manage to duplicate some of my efforts on my site
>>> with Python I will be happy to upload the code to my site. I will also
>>> try to upload working exec files of such also, except my previous
>>> attempts at downloading the relevant software was blocked by AVG
>>> software as risky.
>>>
>>> Gordon
>>>
>>>
>>> Liberty Basic for n = 32 to 255: print n;chr$(n) : next n
>>
>> I grew up on BBC basic in 1984. Not used thereafter.
>>
>> Your first one is (I guess) this in python:
>>
> for i in range(32,127):
>> ...   print chr(i),
>> ...
>>   ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C
>>   D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f
>>   g h i j k l m n o p q r s t u v w x y z { | } ~
>>
>>
>>> REM BBC Basic FOR c = 1 TO 15 : COLOUR c
>>>   PRINT "Color ";c
>>> NEXT c
>>>
>>> REM BBC Basic c = 0 FOR x = 80 TO 2000 STEP 96
>>>   GCOL c: CIRCLE FILL x,500,50 : c = c + 1
>>> NEXT x
>>
>> If you tell us some more of what color, gcol etc do someone will likely
>> show you Though in all fairness I dont expect it to be as pithy as the
>> BASIC --
>> https://mail.python.org/mailman/listinfo/python-list
> 
> The color stuff has to do with DOS based 16 color displays I think.
> Or maybe it worked with other 16 color displays of the time

No
If that code is BBC basic then it would print the word Colour followed by 
the numbers 1 - 15

For x in range (1,16):
print "Colour %s"%x



-- 
fat electrons in the lines
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Untrusted code execution

2016-04-05 Thread Chris Angelico
On Wed, Apr 6, 2016 at 3:52 AM, Ian Kelly  wrote:
> On Tue, Apr 5, 2016 at 11:48 AM, Chris Angelico  wrote:
>> Your code is a *lot* safer for using 'eval' rather than 'exec'.
>> Otherwise, you'd be easily exploited using exceptions, which carry a
>> ton of info. But even so, I would not bet money (much less the
>> security of my systems) on this being safe.
>
> Not to mention "import". :-P

Nah. That one's easy to blank out. Once you go to a restricted
builtins, the import statement breaks:

>>> def safe_exec(untrusted_code):
... tree = compile(untrusted_code, "

Re: Best Practices for Internal Package Structure

2016-04-05 Thread Ethan Furman

On 04/04/2016 06:43 PM, Steven D'Aprano wrote:

On Tue, 5 Apr 2016 02:47 am, Josh B. wrote:


My package, available at https://github.com/jab/bidict, is currently laid
out like this:

bidict/
├── __init__.py
├── _bidict.py
├── _common.py
├── _frozen.py
├── _loose.py
├── _named.py
├── _ordered.py
├── compat.py
├── util.py



The purpose of packages isn't enable Java-style "one class per file" coding,
especially since *everything* in the package except the top level "bidict"
module itself is private. bidict.compat and bidict.util aren't flagged as
private, but they should be, since there's nothing in either of them that
the user of a bidict class should care about.


Agreed.



(utils.py does export a couple of functions, but they should be in the main
module, or possibly made into a method of BidirectionalMapping.)

Your package is currently under 500 lines. As it stands now, you could
easily flatten it to a single module:

bidict.py


Yup... well, actually you could just stick it in __init__.py.


Unless you are getting some concrete benefit from a package structure, you
shouldn't use a package just for the sake of it. Even if the code doubles
in size, to 1000 lines, that's still *far* below the point at which I
believe a single module becomes unwieldy just from size. At nearly 6500
lines, the decimal.py module is, in my opinion, *almost* at the point where
just size alone suggests splitting the file into submodules. Your module is
nowhere near that point.


Well, there should be one more module:

  test.py

So in total, two files

bidict/
|-- __init__.py
|-- test.py

will do the trick.  Oh, and you want a README, LICENSE, a doc file.  And 
that should do it.  :)


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


Re: Best Practices for Internal Package Structure

2016-04-05 Thread Ethan Furman

On 04/05/2016 10:38 AM, Sven R. Kunze wrote:

On 05.04.2016 03:43, Steven D'Aprano wrote:

The purpose of packages isn't enable Java-style "one class per file"
coding,
especially since *everything* in the package except the top level
"bidict"
module itself is private. bidict.compat and bidict.util aren't flagged as
private, but they should be, since there's nothing in either of them that
the user of a bidict class should care about.

(utils.py does export a couple of functions, but they should be in the
main
module, or possibly made into a method of BidirectionalMapping.)

Your package is currently under 500 lines. As it stands now, you could
easily flatten it to a single module:

bidict.py


I don't recommend this.

The line is blurry but 500 is definitely too much. Those will simply not
fit on a 1 or 2 generous single screens anymore (which basically is our
guideline). The intention here is to always have a bit more of a full
screen of code (no wasted pixels) while benefiting from switching to
another file (also seeing a full page of other code).


I do.  I have modules ranging from 1300+, 1800+, and nearly 10,000 
lines.  The only one I'm considering refactoring is the 10,000 line one; 
the others are just fine and would only suffer from being split up.


Possibly a good rule of thumb:  If a module is useful on its own (a 
bunch of utilities, or a bunch of data types, or a specific class with 
lots of utilities just for that class) then it's okay by itself; 
otherwise, combine it with the module it's used in.


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


Re: Best Practices for Internal Package Structure

2016-04-05 Thread Sven R. Kunze

On 05.04.2016 19:59, Chris Angelico wrote:

On Wed, Apr 6, 2016 at 3:38 AM, Sven R. Kunze  wrote:

Your package is currently under 500 lines. As it stands now, you could
easily flatten it to a single module:

bidict.py


I don't recommend this.

The line is blurry but 500 is definitely too much. Those will simply not fit
on a 1 or 2 generous single screens anymore (which basically is our
guideline). The intention here is to always have a bit more of a full screen
of code (no wasted pixels) while benefiting from switching to another file
(also seeing a full page of other code).

Clearly this is a matter of opinion. I have absolutely no problem with
a 500-lne file. As soon as you force people to split things across
files, you add a new level of indirection that causes new problems.


Guidelines. No forcing.


I'd rather keep logically-related code together rather than splitting
across arbitrary boundaries;


That's a good advice and from what I can see bidict adheres to that. ;)


you can always search within a file for the bit you want.


If you work like in the 80's, maybe. Instead of scrolling, (un)setting 
jumppoints, or use splitview of the same file, it's just faster/easier 
to jump between separate files in todays IDEs if you need to jump 
between 4 places within 3000 lines of code.



When you split a file into two, you duplicate the
headers at the top (imports and stuff), so you'll split a 100-line
file into two 60-line files or so. Do that to several levels in a big
project and you end up with a lot more billable lines of code, but no
actual improvement.


Who cares about the imports? As I said somewhere else in my response, 
it's hidden from sight if you use a modern IDE. We call that folding. ;)


Who bills lines of code? Interesting business model. ;)


I guess that's worth doing - lovely billable hours
doing the refactoring,


Refactoring is not just splitting files if that concept is new to you.

Refactoring it not an end to itself. It serves a purpose.


more billable hours later on when you have to
read past the migration in source control ("where did this line come
from" gets two answers all the time), and more billable hours dealing
with circular imports when two fragments start referring to each
other. Sounds like a plan.


It appears to me as if you like messy code then. ;)

Best,
Sven
--
https://mail.python.org/mailman/listinfo/python-list


Re: Promoting Python

2016-04-05 Thread BartC

On 05/04/2016 19:02, alister wrote:

On Tue, 05 Apr 2016 08:06:02 -0400, Joel Goldstick wrote:



REM BBC Basic FOR c = 1 TO 15 : COLOUR c
   PRINT "Color ";c
NEXT c

REM BBC Basic c = 0 FOR x = 80 TO 2000 STEP 96
   GCOL c: CIRCLE FILL x,500,50 : c = c + 1
NEXT x


If you tell us some more of what color, gcol etc do someone will likely
show you Though in all fairness I dont expect it to be as pithy as the
BASIC --
https://mail.python.org/mailman/listinfo/python-list


The color stuff has to do with DOS based 16 color displays I think.
Or maybe it worked with other 16 color displays of the time


No
If that code is BBC basic then it would print the word Colour followed by
the numbers 1 - 15

For x in range (1,16):
print "Colour %s"%x



You forgot the COLOUR statement. Presumably each line is in a different 
text colour.


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


Re: Untrusted code execution

2016-04-05 Thread Jon Ribbens
On 2016-04-05, Chris Angelico  wrote:
> On Wed, Apr 6, 2016 at 3:26 AM, Jon Ribbens
> wrote:
>> The received wisdom is that restricted code execution in Python is
>> an insolubly hard problem, but it looks a bit like my 7-line example
>> above disproves this theory, provided you choose carefully what you
>> provide in your restricted __builtins__ - but people who knows more
>> than me about Python seem to have thought about this problem for
>> longer than I have and come up with the opposite conclusion so I'm
>> curious what I'm missing.
>
> No, it doesn't disprove anything. All you've shown is "here's a piece
> of code that hasn't yet been compromised". :)

Yes, obviously. I wasn't asking for pedantry.

> Your code is a *lot* safer for using 'eval' rather than 'exec'.
> Otherwise, you'd be easily exploited using exceptions, which carry a
> ton of info.

... but all in attributes that don't start with "_", as far as I can see.

I think a very similar approach would work with 'exec' too, just you
would obviously have to disallow ast.Import and ast.ImportFrom.

> But even so, I would not bet money (much less the security of my
> systems) on this being safe.

I wasn't planning on betting any money ;-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Request to mailing list Python-list rejected

2016-04-05 Thread Tim Golden

On 05/04/2016 08:34, Oscar Benjamin wrote:

On 5 Apr 2016 03:50,  wrote:


Your request to the Python-list mailing list

 Posting of your message titled "Re: Plot/Graph"

has been rejected by the list moderator.  The moderator gave the
following reason for rejecting your request:

"Your message was too big; please trim unnecessary content."

Any questions or comments should be directed to the list administrator
at:

 [email protected]


When did this start happening?

The message in question includes a big block of code posted by someone else
as context. My comment was that the code was incomplete so I felt it
reasonable to include it as context.



It wasn't I who rejected it, but for accuracy's sake: the list does in 
fact have an upper size limit, beyond which posts are automatically held 
for moderation. My own policy is -- if the post is clearly pukka as I 
imagine yours would have been -- to let it through. Presumably in this 
case one of the other moderators was feeling rather more zealous and 
decided to bounce it. I'll let him speak for himself if he wishes.


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


Re: Untrusted code execution

2016-04-05 Thread Jon Ribbens
On 2016-04-05, Chris Angelico  wrote:
> You can also create objects of various types using literal/display
> syntax, and that might let you craft some weird construct that
> effectively access those attributes without actually having an
> attribute that starts with an underscore. (Think of "getattr(x,
> '\x5f_class__')", although obviously it'll take more work than that,
> since getattr itself isn't available.)

Indeed. Although I think it would be safe to add a "proxy" getattr()
to the namespace's __builtins__ that just checked if the first
character of "name" was "_" and if so raised an AttributeError or
somesuch, and otherwise passed straight through to the real getattr(),
e.g.:

def proxy_getattr(obj, name, *args):
if type(name) is str and not name.startswith("_"):
return getattr(obj, name, *args)
raise AttributeError("Not allowed to access private attributes")
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Untrusted code execution

2016-04-05 Thread Jon Ribbens
On 2016-04-05, Jon Ribbens  wrote:
> On 2016-04-05, Chris Angelico  wrote:
>> Your code is a *lot* safer for using 'eval' rather than 'exec'.
>> Otherwise, you'd be easily exploited using exceptions, which carry a
>> ton of info.
>
> ... but all in attributes that don't start with "_", as far as I can see.

Sorry, obviously I meant "that *do* start with '_'".
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Promoting Python

2016-04-05 Thread alister
On Tue, 05 Apr 2016 19:47:00 +0100, BartC wrote:

> On 05/04/2016 19:02, alister wrote:
>> On Tue, 05 Apr 2016 08:06:02 -0400, Joel Goldstick wrote:
> 
> REM BBC Basic FOR c = 1 TO 15 : COLOUR c
>PRINT "Color ";c
> NEXT c
>
> REM BBC Basic c = 0 FOR x = 80 TO 2000 STEP 96
>GCOL c: CIRCLE FILL x,500,50 : c = c + 1
> NEXT x

 If you tell us some more of what color, gcol etc do someone will
 likely show you Though in all fairness I dont expect it to be as
 pithy as the BASIC --
 https://mail.python.org/mailman/listinfo/python-list
>>>
>>> The color stuff has to do with DOS based 16 color displays I think.
>>> Or maybe it worked with other 16 color displays of the time
>>
>> No If that code is BBC basic then it would print the word Colour
>> followed by the numbers 1 - 15
>>
>> For x in range (1,16):
>>  print "Colour %s"%x
>>
>>
> You forgot the COLOUR statement. Presumably each line is in a different
> text colour.

indeed i did
I am no-longer in the old basic habit of putting as many statements on a 
line as possible.

Perhaps this is where the constant requests for a one line solution 
originate? 



-- 
Price's Advice:
It's all a game -- play it to have fun.
-- 
https://mail.python.org/mailman/listinfo/python-list


mod_wsgi not compatible with Wamp 2.4 and python 3.4.3

2016-04-05 Thread asimkon .
I am using Apache to develop Python Web applications via Django. As i am
new to python web development, i am having problem to find the right
version for mod_wsgi.so (compiled version for Apache 2.4.4 - WampServer 2.4
- and python 3.4.3 latest version from ActivePython on Windows x86) and i
get a 500 internal server error "The server encountered an internal error
or misconfiguration and was unable to complete your request".

when i try to run the following script:

def application(environment, start_response):
status = '200 OK'
response_headers = [('Content-type', 'text/html')]
start_response(status, response_headers)
page = """


Hello world!
This is being served using mod_wsgi


"""
return page

I just found the following link
http://grapevine.dyndns-ip.com/download/folder.asp?eid=33&folder=%2Fdownload%2Fapache%2Fmod_wsgi-windows-4.4.6%2Fmod_wsgi-windows-4.4.6%2Fapache24-win32-vc10%2Fmodules%2F
but unfortunately i have got incompatibility problems with the compiled
files mentioned. Any kind of help would be convenient to me.

I am looking for the compiled (.so file) version, as it will save me from a
lot of trouble.

Regards
Kostas  Asimakopoulos
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best Practices for Internal Package Structure

2016-04-05 Thread Sven R. Kunze

On 05.04.2016 20:40, Ethan Furman wrote:


(utils.py does export a couple of functions, but they should be in 
the main

module, or possibly made into a method of BidirectionalMapping.)

Your package is currently under 500 lines. As it stands now, you could
easily flatten it to a single module:

bidict.py


Yup... well, actually you could just stick it in __init__.py.


Interesting. We did (and I started it) a similar thing for some packages 
which then grew unbearably in a single year.



Now, everybody in team agrees with: 'who idiot put this stuff in 
__ini__.py?' It was me who started it so I take it with a smile. But 
it's definitely a wart.


So, we have a new guideline since then: "empty __init__.py" if possible 
of course; you sometimes need to collect/do magic imports but that's a 
separate matter.



Best,
Sven
--
https://mail.python.org/mailman/listinfo/python-list


Best practices for single file modules Inspired by: Best Practices for Internal Package Structure

2016-04-05 Thread Eric S. Johansson
I was inspired by the thread on packaging practices discussion with 
bidict to ask a related question which is what are the best practices 
with packaging/releasing a single file Python module ?


Back story: I'm always creating little bits of useful code that I want 
to reuse (for example, recursive expansion template module). It seems 
like the overhead of setting up a module is a bit high for a single file 
module but maybe this modern nation I'm not aware of or template based 
techniques that would lower the setup overhead.

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


Re: Best Practices for Internal Package Structure

2016-04-05 Thread Michael Selik


> On Apr 5, 2016, at 7:49 PM, Sven R. Kunze  wrote:
> 
>> On 05.04.2016 19:59, Chris Angelico wrote:
>> On Wed, Apr 6, 2016 at 3:38 AM, Sven R. Kunze  wrote:
 Your package is currently under 500 lines. As it stands now, you could
 easily flatten it to a single module:
 
 bidict.py
>>> 
>>> I don't recommend this.
>>> 
>>> The line is blurry but 500 is definitely too much. Those will simply not fit
>>> on a 1 or 2 generous single screens anymore (which basically is our
>>> guideline). The intention here is to always have a bit more of a full screen
>>> of code (no wasted pixels) while benefiting from switching to another file
>>> (also seeing a full page of other code).
>> Clearly this is a matter of opinion. I have absolutely no problem with
>> a 500-lne file. As soon as you force people to split things across
>> files, you add a new level of indirection that causes new problems.
> 
> Guidelines. No forcing.
> 
>> I'd rather keep logically-related code together rather than splitting
>> across arbitrary boundaries;
> 
> That's a good advice and from what I can see bidict adheres to that. ;)
> 
>> you can always search within a file for the bit you want.
> 
> If you work like in the 80's, maybe. Instead of scrolling, (un)setting 
> jumppoints, or use splitview of the same file, it's just faster/easier to 
> jump between separate files in todays IDEs if you need to jump between 4 
> places within 3000 lines of code.

When you made that suggestion earlier, I immediately guessed that you were 
using PyCharm. I agree that the decision to split into multiple files or keep 
everything in just a few files seems to be based on your development tools. I 
use IPython and SublimeText, so my personal setup is more suited to one or a 
few files.

>> When you split a file into two, you duplicate the
>> headers at the top (imports and stuff), so you'll split a 100-line
>> file into two 60-line files or so. Do that to several levels in a big
>> project and you end up with a lot more billable lines of code, but no
>> actual improvement.
> 
> Who cares about the imports? As I said somewhere else in my response, it's 
> hidden from sight if you use a modern IDE. We call that folding. ;)
> 
> Who bills lines of code? Interesting business model. ;)
> 
>> I guess that's worth doing - lovely billable hours
>> doing the refactoring,
> 
> Refactoring is not just splitting files if that concept is new to you.
> 
> Refactoring it not an end to itself. It serves a purpose.
> 
>> more billable hours later on when you have to
>> read past the migration in source control ("where did this line come
>> from" gets two answers all the time), and more billable hours dealing
>> with circular imports when two fragments start referring to each
>> other. Sounds like a plan.
> 
> It appears to me as if you like messy code then. ;)
> 
> Best,
> Sven
> -- 
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Untrusted code execution

2016-04-05 Thread Chris Angelico
On Wed, Apr 6, 2016 at 4:50 AM, Jon Ribbens
 wrote:
> On 2016-04-05, Chris Angelico  wrote:
>> On Wed, Apr 6, 2016 at 3:26 AM, Jon Ribbens
>> wrote:
>>> The received wisdom is that restricted code execution in Python is
>>> an insolubly hard problem, but it looks a bit like my 7-line example
>>> above disproves this theory, provided you choose carefully what you
>>> provide in your restricted __builtins__ - but people who knows more
>>> than me about Python seem to have thought about this problem for
>>> longer than I have and come up with the opposite conclusion so I'm
>>> curious what I'm missing.
>>
>> No, it doesn't disprove anything. All you've shown is "here's a piece
>> of code that hasn't yet been compromised". :)
>
> Yes, obviously. I wasn't asking for pedantry.

It's more than pedantry. There's a huge difference between "thing that
hasn't been proven yet" and "thing that has been disproved".

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


Re: Request to mailing list Python-list rejected

2016-04-05 Thread Ethan Furman

On 04/05/2016 12:12 PM, Tim Golden wrote:

On 05/04/2016 08:34, Oscar Benjamin wrote:



When did this start happening?

The message in question includes a big block of code posted by someone
else
as context. My comment was that the code was incomplete so I felt it
reasonable to include it as context.


It wasn't I who rejected it, but for accuracy's sake: the list does in
fact have an upper size limit, beyond which posts are automatically held
for moderation. My own policy is -- if the post is clearly pukka as I
imagine yours would have been -- to let it through. Presumably in this
case one of the other moderators was feeling rather more zealous and
decided to bounce it. I'll let him speak for himself if he wishes.


Twas I that did it.  I find it highly aggravating to scroll through 
pages of quoted whatever for a simple comment at the end.  If it's not a 
PEP, or obviously non-quoted anywhere-close-to-on-topic content, I bounce.


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


Re: Best Practices for Internal Package Structure

2016-04-05 Thread Ethan Furman

On 04/05/2016 12:09 PM, Sven R. Kunze wrote:

On 05.04.2016 20:40, Ethan Furman wrote:

Steven D'Aprano wrote:



Your package is currently under 500 lines. As it stands now, you could
easily flatten it to a single module:

bidict.py


Yup... well, actually you could just stick it in __init__.py.


Interesting. We did (and I started it) a similar thing for some packages
which then grew unbearably in a single year.

Now, everybody in team agrees with: 'who idiot put this stuff in
__ini__.py?' It was me who started it so I take it with a smile. But
it's definitely a wart.

So, we have a new guideline since then: "empty __init__.py" if possible
of course; you sometimes need to collect/do magic imports but that's a
separate matter.


For application level stuff, sure.  I mostly write various utilities 
where one __init__.py and one test.py fill the bill.  I see `bidict` as 
a utility-class item, though.


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


Re: Import graphics error

2016-04-05 Thread Thomas 'PointedEars' Lahn
Nicolae Morkov wrote:

> […]
> *Following the instructions I copied The graphic modules by John Zelle in
> Python folder in Lib folder *
> **And when I installed graphic library the error was :* *
> 
> Traceback (most recent call last):
> File
> "C:/Users/Nicolae/AppData/Local/Programs/Python/Python35/pythonK/pr.py",
> line 1, in 
> from graphics import GraphicsWindow
> ImportError: cannot import name 'GraphicsWindow'

| >>> from email import ID10T
| Traceback (most recent call last):
|   File "", line 1, in 
| ImportError: cannot import name 'ID10T'



-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best practices for single file modules Inspired by: Best Practices for Internal Package Structure

2016-04-05 Thread Ethan Furman

On 04/05/2016 12:49 PM, Eric S. Johansson wrote:


I was inspired by the thread on packaging practices discussion with
bidict to ask a related question which is what are the best practices
with packaging/releasing a single file Python module ?

Back story: I'm always creating little bits of useful code that I want
to reuse (for example, recursive expansion template module). It seems
like the overhead of setting up a module is a bit high for a single file
module but maybe this modern nation I'm not aware of or template based
techniques that would lower the setup overhead.


The problem I have found with single file PyPI packages is what to do 
with the related files?  README, LICENSE, doc, test, ... ?


I ended up with (for example): dbf.py, dbf_test.py, dbf.README, ..., and 
it was a mess.


So, even for single-purpose utilities I just make a package and stuff 
the main content into __init__.py, my tests in test.py, and other 
supporting files in that same folder.


So far it has worked well for me.

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


Re: Install request

2016-04-05 Thread Mark Lawrence via Python-list

On 05/04/2016 16:56, Igor Korot wrote:

  Hi, python community,
Recently there was a huge number of e-mail stating that the python
installer does not work.

When asked about it, people reveal that they wee using Windows and
they were getting
errors about missing DLL.

I know for a fact that in the InstallShield it is possible to detect
the OS you are trying
to install on.

So, here is my request: if its not possible to include the DLL in
question in the installer,
can the installer check for the OS version and ask the user to go to
Microsoft.com,
download and install the library?

It looks like people don't want to use their common sense and just
wanted to waste
everybody's time by asking what went wrong instead of just download
the dll executable
from MS site and install it.

Can something like this be done to eliminate those questions in the
future and let people
concentrate on the real python issues?

Thank you.



I fail to see why anybody in the Python community should put themselves 
out to answer a question for someone who is too bone idle to do any 
research in the first place, especially when the question has been asked 
and answered repeatadly over a period of months.  For those who 
disagree, they can provide the patches, or the edits to a wiki as 
appropriate.


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

Mark Lawrence

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


Re: mod_wsgi not compatible with Wamp 2.4 and python 3.4.3

2016-04-05 Thread justin walters
On Apr 5, 2016 12:51 PM, "asimkon ."  wrote:
>
> I am using Apache to develop Python Web applications via Django. As i am
> new to python web development, i am having problem to find the right
> version for mod_wsgi.so (compiled version for Apache 2.4.4 - WampServer
2.4
> - and python 3.4.3 latest version from ActivePython on Windows x86) and i
> get a 500 internal server error "The server encountered an internal error
> or misconfiguration and was unable to complete your request".
>
> when i try to run the following script:
>
> def application(environment, start_response):
> status = '200 OK'
> response_headers = [('Content-type', 'text/html')]
> start_response(status, response_headers)
> page = """
> 
> 
> Hello world!
> This is being served using mod_wsgi
> 
> 
> """
> return page
>
> I just found the following link
>
http://grapevine.dyndns-ip.com/download/folder.asp?eid=33&folder=%2Fdownload%2Fapache%2Fmod_wsgi-windows-4.4.6%2Fmod_wsgi-windows-4.4.6%2Fapache24-win32-vc10%2Fmodules%2F
> but unfortunately i have got incompatibility problems with the compiled
> files mentioned. Any kind of help would be convenient to me.
>
> I am looking for the compiled (.so file) version, as it will save me from
a
> lot of trouble.
>
> Regards
> Kostas  Asimakopoulos
> --
> https://mail.python.org/mailman/listinfo/python-list

Have you tried using apache as a proxy server to forward requests to a
dedicated wsgi server such as gunicorn instead of using mod_wsgi? I find
it's a lot easier to set up.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best Practices for Internal Package Structure

2016-04-05 Thread Mark Lawrence via Python-list

On 05/04/2016 19:49, Sven R. Kunze wrote:


It appears to me as if you like messy code then. ;)



The messy code is with the person who needlessly splits a single module 
of a few thousand lines into several modules just for the sake of it. 
If you want to play yo-yo, leaping from source file to source file, 
running the risk of circular imports, feel free, I won't lose any sleep 
over it, but give me one, clean file any day of the week.


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

Mark Lawrence

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


Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-05 Thread Michael Selik
It seems coding a generic interval and intervalset will bring a variety of 
difficult design choices. If I were you, I'd forget making it generic and build 
one specifically for the application you have in mind. That way you can ignore 
most of these feature discussions.

> On Apr 5, 2016, at 2:59 PM, Random832  wrote:
> 
>> On Tue, Apr 5, 2016, at 04:11, Nagy László Zsolt wrote:
>> But there is still need to check begin <= end. But maybe
>> you are right: if we suppose that nobody will try to use an interval
>> where end < begin then we can use plain tuples. But then the user *must*
>> make sure not to use invalid intervals.
> 
> The IntervalSet constructor and add method could switch them or throw an
> exception. But I'm not saying to use plain tuples. I'm saying to make
> Interval a "dumb" object, which *only* supports being constructed and
> added to a set, rather than putting a bunch of set-like operations on
> it.
> 
>> It is blurred by design. There is an interpretation where an interval
>> between [0..4] equals to a set of intervals ([0..2],[2..4]).
> 
> No, because 2.5 is in one and not the other. Floats are orderable with
> ints, so it's not reasonable to say "this is an int intervalset so no
> floats are contained in it". But that's another discussion.
> 
> But why would you want to use [0..4] directly instead of ([0..4])?
> 
>> Actually,
>> you can ask: "is an element within the interval?" The same question can
>> be asked for an Interval set. So the same type of value can be
>> "contained" within an interval and also witin an interval set. In the
>> current implementation, if you try to create a set with these two
>> intervals [0..2] and [2..4], then they are unified into a single element
>> on purpose: to make sure that there is only a single official
>> representation of it. E.g. ([0..2],[2..4]) is not a valid set, only
>> ([0..4]) is.
> 
> Uh, exactly. I don't understand why any of this makes it useful to have
> these operations on interval objects.
> 
>> By definition, a set is given with its elements, e.g. for any possible
>> item, you can tell if it is part of the set or not. So if
>> ([0..2],[2..4]) and ([0..4]) have exactly the same elements (by the
>> given definition), then they are not just equal: they are the same set.
>> The same reasoning is used in math when they say: there cannot be
>> multiple empty sets. There exists a single empty set. It happens that we
>> can only represent a finite number of elements in any set on a computer.
>> I wanted to have a well defined single way to represent any given set.
> 
> What? *I* am the one who wants a well defined single way to represent a
> given set. *You* are the one who wants to make [0..4] a set-like object
> that is different from ([0..4]) and doesn't quite support the same
> operations.
> 
>> I can also see your point. From another point a view, a set and a set of
>> sets is not the same type.
> 
> I'm saying an interval is _not_ a set. It is merely part of the way of
> describing the set. Just like the word "of" isn't a set just because
> "the set of all even numbers" is a set.
> 
> You could consider "the set of [dates|numbers|etc] in a single interval"
> to be a type of set, certainly. But there's no reason to have such a set
> _not_ fully support set operations even when those operations will not
> return a set of a single interval.
> 
>> However, I do not share this view, because if
>> we start thinking this way, then operations like the one below does not
>> make sense:
>> 
>> [0..4]) - (1..2] == [0..1] | [2..4]
>> 
>> If you make a strinct distinction between intervals and interval sets,
>> then the above equation does not make sense, because you cannot remove
>> an element from a set that is not an "element" of it. The above equation
>> makes sense only if the "intervalset" is a general representation of
>> possible values, and the "interval" type is a special representation of
>> (the same) possible values.
> 
> I don't understand why you want to let the user use the "interval" type
> for purposes other than adding to an intervalset in the first place
> Nothing you've posted has explained this.
> 
>> It is clear when you ask the question: "is 3
>> in the interval?" and you can also ask "is 3 in the interval set?"
>> - so
>> the value of the same type can be contained in the interval and also in
>> the interval set. Maybe the naming is bad, and it should be named
>> "Intervals" instead of IntervalSet?
> -- 
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Import graphics error

2016-04-05 Thread Michael Selik


> On Apr 5, 2016, at 5:17 PM, Nicolae Morkov  wrote:
> 
> I copied the code from Python from everyone page 67.
> Following the instructions The graphic modules by John Zelle I copied  into
> the python lacation ,to be easier to find the path .

Please be more specific. What is the python location? What exactly did you 
copy? How did you copy? What is the exact path where Python is installed, where 
these graphics modules are, and where the code is that you're working on?

> On Tue, Apr 5, 2016 at 11:19 AM, Nicolae Morkov 
> wrote:
> 
>> # This program creates a graphics window with a rectangle. It provides the
>> 3 # template used with all of the graphical programs used in the book.
>> 4 #
>> 5
>> 6 from graphics import GraphicsWindow
>> 7
>> 8 # Create the window and access the canvas.
>> 9  win = GraphicsWindow()
>> 10 canvas = win.canvas()
>> 11
>> 12 # Draw on the canvas.
>> 13 canvas.drawRect(5, 10, 20, 30)
>> 14
>> 15 # Wait for the user to close the window.
>> 16 win.wait()
>> 
>> 
>> *This is the error I get*
>> 
>> Traceback (most recent call last):
>>  File
>> "C:/Users/Nicolae/AppData/Local/Programs/Python/Python35/pythonK/pr.py",
>> line 1, in 
>>from graphics import GraphicsWindow
>> ImportError: No module named 'graphics'
>> 
>> 
>> *And when I installed graphic library the error was :*
>> 
>> Traceback (most recent call last):
>>  File
>> "C:/Users/Nicolae/AppData/Local/Programs/Python/Python35/pythonK/pr.py",
>> line 1, in 
>>from graphics import GraphicsWindow
>> ImportError: cannot import name 'GraphicsWindow'
> -- 
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Untrusted code execution

2016-04-05 Thread Paul Rubin
Jon Ribbens  writes:
>> isinstance(node, ast.Attribute) and node.attr.startswith("_")):
>> raise ValueError("Access to private values is not allowed.")
>> namespace = {"__builtins__": {"int": int, "str": str, "len": len}}

> Nobody has any thoughts on this at all?

What happens with foo.get("5F5F70726976617465".decode("hex")) ?
That string decodes to "__private".

The Bastion module was removed some time ago because every attempt to do
something like this has failed...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python script for .dat file

2016-04-05 Thread Michael Selik
What code have you written so far?

> On Apr 5, 2016, at 5:27 PM, Muhammad Ali  wrote:
> 
>> On Tuesday, April 5, 2016 at 9:07:54 AM UTC-7, Oscar Benjamin wrote:
>>> On 5 April 2016 at 16:44, Muhammad Ali  wrote:
 On Tuesday, April 5, 2016 at 8:30:27 AM UTC-7, Joel Goldstick wrote:
 On Tue, Apr 5, 2016 at 11:23 AM, Muhammad Ali
  wrote:
> 
> Could any body tell me a general python script to generate .dat file 
> after the extraction of data from more than 2 files, say file A and file 
> B?
> 
> Or could any body tell me the python commands to generate .dat file after 
> the extraction of data from two or more than two files?
> 
> I have to modify some python code.
 
 What exactly is a .dat file? and how is it different from any other
 file? Is it binary or text data?
>>> 
>>> It is text data.
>> 
>> You haven't provided enough information for someone to answer your
>> question. This is a text mailing list so if a .dat file is text then
>> you can paste here an example of what it would look like. What would
>> be in your input files and what would be in your output files? What
>> code have you already written?
>> 
>> If the file is large then don't paste its entire content here. Just
>> show an example of what the data would look like if it were a smaller
>> file (maybe just show the first few lines of the file).
>> 
>> Probably what you want to do is easily achieved with basic Python
>> commands so I would recommend to have a look at a tutorial. There are
>> some listed here:
>> https://wiki.python.org/moin/BeginnersGuide/NonProgrammers
>> 
>> Also the tutor mailing list is probably more appropriate for this
>> level of question:
>> https://mail.python.org/mailman/listinfo/tutor
>> 
>> --
>> Oscar
> 
> Input and outout files are text files. e.g: 
> #KptCoord #E-E_Fermi #delta_N
>  0.  -22.   0.000E+00
>  0.0707  -22.   0.000E+00
>  0.1415  -22.   0.000E+00
>  0.2122  -22.   0.000E+00
>  0.2830  -22.   0.000E+00
>  0.3537  -22.   0.000E+00
>  0.4245  -22.   0.000E+00
>  0.4952  -22.   0.000E+00
>  0.5660  -22.   0.000E+00
>  0.6367  -22.   0.000E+00
>  0.7075  -22.   0.000E+00
>  0.7782  -22.   0.000E+00
>  0.8490  -22.   0.000E+00
>  0.9197  -22.   0.000E+00
>  0.9905  -22.   0.000E+00
> -- 
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Label behavior's difference between tkinter and ttk

2016-04-05 Thread Terry Reedy

On 4/5/2016 11:10 AM, Mark Lawrence via Python-list wrote:

On 05/04/2016 07:57, ast wrote:


[snip code]

# Enter these commands by hand, in a shell

img.config(foreground='red')
img.config(foreground='lime')
img.config(foreground='yellow')


It looks like a ttk bug, isn't it ?
I am using python 3.5.1

I tried a root.update_idletasks() to refresh the graphic
but it changed nothings.



I'm no tkinter expert, but I do know that there is a huge difference
between the way that tk and ttk widgets are configured.


In this case, it is the embedded tk bitmap image widget that is being 
reconfigured.  The issue is how that propagates the the diplay of the label.


--
Terry Jan Reedy

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


Re: python script for .dat file

2016-04-05 Thread Mark Lawrence via Python-list

On 05/04/2016 21:35, Michael Selik wrote:

What code have you written so far?



Would you please not top post on this list, it drives me nuts!!!

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

Mark Lawrence

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


good way to avoid recomputations?

2016-04-05 Thread Maurice
Hi. I working on a project where I have 5 scripts loading the same file at the 
very beginning so I would like to know the best way I can get this file without 
having to compute it 5 times.

I also perform, in all the scripts, a list comprehension using this file that 
takes 30s to run. Would be cool to always have access to it as well.

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


Re: good way to avoid recomputations?

2016-04-05 Thread Erik

Hi Maurice,

On 05/04/16 21:54, Maurice wrote:

Hi. I working on a project where I have 5 scripts loading the same
file at the very beginning so I would like to know the best way I can
get this file without having to compute it 5 times.

I also perform, in all the scripts, a list comprehension using this
file that takes 30s to run. Would be cool to always have access to it
as well.


It sort of depends on what data you are extracting from the file (so 
expect people to ask for more information), but my initial gut reaction 
is to suggest writing a class that ingests the file.


Create an object of that class, giving it the filename to ingest, and 
then use it in each of the 5 places.


Or  are you saying that each script is entirely separate? If so, 
then one approach might be to write a single script that "loads" the 
file and runs the comprehension and then "pickle" (look it up in the 
docs) the resulting structure. Your other scripts can then load the 
pickled version of the pre-computed comprehension much faster.


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


Re: Untrusted code execution

2016-04-05 Thread Jon Ribbens
On 2016-04-05, Paul Rubin  wrote:
> Jon Ribbens  writes:
>>> isinstance(node, ast.Attribute) and node.attr.startswith("_")):
>>> raise ValueError("Access to private values is not allowed.")
>>> namespace = {"__builtins__": {"int": int, "str": str, "len": len}}
>
>> Nobody has any thoughts on this at all?
>
> What happens with foo.get("5F5F70726976617465".decode("hex")) ?
> That string decodes to "__private".

Yes, and? My code wasn't trying to prevent anyone building a string
object starting with an underline, merely to prevent anyone accessing
identifiers and attributes that start with an underline. The namespace
I was suggesting didn't provide access to any objects which have a
'get()' method which would access attributes.

> The Bastion module was removed some time ago because every attempt
> to do something like this has failed...

Bastion was removed because rexec was removed. rexec was very
ambitious - it was trying to allow completely arbitrary Python code
to run in a restricted namespace. That's basically impossible since
Python 2.2.

My method is doing something different - it's inspecting the code
before it's run, to prevent the methods by which people would easily
escape rexec's environment.

Originally, rexec existed and was thought to be 'safe'. Then the
new-style classes were added in Python 2.2, which made rexec unsafe,
so it was disabled because there was no easy way to fix it. Then
in Python 2.5 the new AST parser was added, which I think perhaps
does provide a way to fix rexec (or at least something rexec-like),
but nobody was clamoring for rexec to be reinstated so nobody looked
into what ast could do for rexec.

... unless I'm missing something obvious (or subtle!)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python script for .dat file

2016-04-05 Thread Joel Goldstick
On Tue, Apr 5, 2016 at 4:47 PM, Mark Lawrence via Python-list
 wrote:
> On 05/04/2016 21:35, Michael Selik wrote:
>>
>> What code have you written so far?
>>
>
> Would you please not top post on this list, it drives me nuts!!!
>
>
A short drive? ;)

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Label behavior's difference between tkinter and ttk

2016-04-05 Thread Terry Reedy

On 4/5/2016 2:57 AM, ast wrote:

Hello

I currently migrate a GUI from tkinter to ttk and I found a problem

Here is a piece of code, with comments which explain what is wrong.


Here is a complete program that eliminates manual entry and uses 
.mainloop and .after for the delays.


import tkinter as tk
import tkinter.ttk as ttk

root = tk.Tk()

BITMAP0 = """
#define zero_width 24
#define zero_height 32
static char zero_bits[] = {
0x00,0x00,0x00, 0x00,0x00,0x00, 0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f,
0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00,
0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f,
0x00,0x00,0x00, 0x00,0x00,0x00, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f,
0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00,
0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f,
0x00,0x00,0x00, 0x00,0x00,0x00, 0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f,
0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00
};
"""

img = tk.BitmapImage(data=BITMAP0, foreground='white', background='black')
label_tk = tk.Label(root, image=img)
label_ttk = ttk.Label(root, image=img)
label_tk.pack()
label_ttk.pack()
colors = ('red', 'lime', 'yellow')
def newcolor(n):
img.config(foreground=colors[n])
n += 1
if n < len(colors):
root.after(1000, newcolor, n)
root.after(1000, newcolor, 0)
root.mainloop()


# The graphic is not refreshed after entering following commands
# when Label comes from ttk. You have to fly over the label with # the
mouse to get the right color.


The reconfiguration is now automatic, but the result is the same.  The 
tk label image changes, the ttk label image does not without mousing 
over the label (making it 'active')



It looks like a ttk bug, isn't it ?


Perhaps.  If we do not get an answer, I might post a Stackoverflow 
question.  Then the tracker.


The difference between tk and ttk Label image options is that the latter 
can have multiple images for different states.  But the single option 
should be used in all states.


A general difference for ttk is the state vector.  Mouse over changes 
the state to active, so for Label, ttk looks to see if there is an image 
for the active state



I am using python 3.5.1


Ditto, on Windows.


I tried a root.update_idletasks() to refresh the graphic
but it changed nothings.


Ditto for root.update().  Both are incorporated in .mainloop().

--
Terry Jan Reedy

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


Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-05 Thread Nagy László Zsolt

>> It is blurred by design. There is an interpretation where an interval
>> between [0..4] equals to a set of intervals ([0..2],[2..4]).
> No, because 2.5 is in one and not the other. 
My notation was: 0..4 for any number between 0 and 4. And 2..4 for any
number between 2 and 4. So yes, 2.5 is in both of them.

> Floats are orderable with
> ints, so it's not reasonable to say "this is an int intervalset so no
> floats are contained in it". But that's another discussion.
I did not say such thing.
>
> But why would you want to use [0..4] directly instead of ([0..4])?
I did not say that I want to use it. I just said that ([0..2], [2..4])
and ([0..4]) contains exactly the same values, and I wanted to have a
single well defined representation.
>> Actually,
>> you can ask: "is an element within the interval?" The same question can
>> be asked for an Interval set. So the same type of value can be
>> "contained" within an interval and also witin an interval set. In the
>> current implementation, if you try to create a set with these two
>> intervals [0..2] and [2..4], then they are unified into a single element
>> on purpose: to make sure that there is only a single official
>> representation of it. E.g. ([0..2],[2..4]) is not a valid set, only
>> ([0..4]) is.
> Uh, exactly. I don't understand why any of this makes it useful to have
> these operations on interval objects.
It doesn't make it a problem. :-)
>
>> By definition, a set is given with its elements, e.g. for any possible
>> item, you can tell if it is part of the set or not. So if
>> ([0..2],[2..4]) and ([0..4]) have exactly the same elements (by the
>> given definition), then they are not just equal: they are the same set.
>> The same reasoning is used in math when they say: there cannot be
>> multiple empty sets. There exists a single empty set. It happens that we
>> can only represent a finite number of elements in any set on a computer.
>> I wanted to have a well defined single way to represent any given set.
> What? *I* am the one who wants a well defined single way to represent a
> given set. *You* are the one who wants to make [0..4] a set-like object
> that is different from ([0..4]) and doesn't quite support the same
> operations.
Are you suggesting, that iterating over a set should yield sets? Just
like iterating over a string yields single character strings? To make it
useful, we must be able to access the begin and end value of such
yielded sets.
>
>> I can also see your point. From another point a view, a set and a set of
>> sets is not the same type.
> I'm saying an interval is _not_ a set. It is merely part of the way of
> describing the set. Just like the word "of" isn't a set just because
> "the set of all even numbers" is a set.
>
> You could consider "the set of [dates|numbers|etc] in a single interval"
> to be a type of set, certainly. But there's no reason to have such a set
> _not_ fully support set operations even when those operations will not
> return a set of a single interval.
Okay, I hope I'm beginning to understand you. Analogy: the ord()
function has a string parameter but it must be of length 1. Simiarily,
when you iterate over a set, the yielded items will be sets with a
"begin" and "end" attribute, wich can only be used when the set has a
single element. Otherwise it should throw an error. The same way my
Interval type throws an error when you try to unify it with a non
overlapping interval. (???)
>
>> However, I do not share this view, because if
>> we start thinking this way, then operations like the one below does not
>> make sense:
>>
>> [0..4]) - (1..2] == [0..1] | [2..4]
>>
>> If you make a strinct distinction between intervals and interval sets,
>> then the above equation does not make sense, because you cannot remove
>> an element from a set that is not an "element" of it. The above equation
>> makes sense only if the "intervalset" is a general representation of
>> possible values, and the "interval" type is a special representation of
>> (the same) possible values.
> I don't understand why you want to let the user use the "interval" type
> for purposes other than adding to an intervalset in the first place
> Nothing you've posted has explained this.
For iteration over the set and accessing begin/end values, of course.
But then again: we could use simple tuples for that, right?

As far as I understand, you recommend to throw out the Interval type,
let the user use simple tuples in the IntervalSet constructor, and let
the iterator iterate over tuples. Right?



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


Re: ANN: intervalset Was: Set type for datetime intervals

2016-04-05 Thread Nagy László Zsolt

>> How about creating two classes for this? One that supports zero sized
>> intervals, and another that doesn't?
> If you don't want zero sized intervals, just don't put any in it. You
> don't have a separate list type to support even integers vs one that
> supports all floats. What operations are made different in
> implementation by this restriction?
When you substract two sets, zero sized intervals may appear in the
result. It is not just a question of "putting or not putting them in".
Are zero sized intervals valid or not? In my particular application,
they are not. I think Michael was right: this cannot be generalized. It
is application dependent.




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


Re: python script for .dat file

2016-04-05 Thread Muhammad Ali
On Tuesday, April 5, 2016 at 2:24:02 PM UTC-7, Joel Goldstick wrote:
> On Tue, Apr 5, 2016 at 4:47 PM, Mark Lawrence via Python-list
>  wrote:
> > On 05/04/2016 21:35, Michael Selik wrote:
> >>
> >> What code have you written so far?
> >>
> >
> > Would you please not top post on this list, it drives me nuts!!!
> >
> >
> A short drive? ;)


> 
> -- 
> Joel Goldstick
> http://joelgoldstick.com/blog
> http://cc-baseballstats.info/stats/birthdays


Would any one paste here some reference/sample python code for such extraction 
of data into text file?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Request to mailing list Python-list rejected

2016-04-05 Thread Thud Foo
On Tue, Apr 5, 2016 at 12:59 PM, Ethan Furman  wrote:

> If it's not a PEP, or obviously non-quoted anywhere-close-to-on-topic
> content, I bounce.
>

​++good​



-- 
I have seen the future and I'm not in it!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python script for .dat file

2016-04-05 Thread Erik

Hi Muhammad,

On 05/04/16 22:49, Muhammad Ali wrote:

Would any one paste here some reference/sample python code for such extraction 
of data into text file?


You haven't really explained what you want to achieve. What is the input 
format, what is the output format, what constraints are there on those 
two formats and the data within them and what transformation between the 
two are you trying to perform?


If you're on a Linux system, then:

$ cat A.dat B.dat C.dat > result.txt

... will do something that is close to what you have asked for so far. 
But I bet it's not what you want.


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


Re: Install request

2016-04-05 Thread Steven D'Aprano
On Wed, 6 Apr 2016 02:52 am, Rustom Mody wrote:

> On Tuesday, April 5, 2016 at 9:49:58 PM UTC+5:30, Oscar Benjamin wrote:
>> Another possibility to improve this situation would be to make a page
>> on the wiki that actually explains the known problems (and fixes) for
>> 3.5 on Windows.
> 
> +10 on that one
> ie When a question becomes a FAQ just put it there


Would somebody who knows Windows actually do this and then post the link
here please?



-- 
Steven

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


Re: python script for .dat file

2016-04-05 Thread Ben Finney
Muhammad Ali  writes:

> Would any one paste here some reference/sample python code for such
> extraction of data into text file?

We're not going to write it for you.

Please show what code you have written so far; a small, self-contained
code example.

Explain what you expect that code to do, and what happens instead, and
how that is different from what you expect.

-- 
 \   “I distrust those people who know so well what God wants them |
  `\to do to their fellows, because it always coincides with their |
_o__)  own desires.” —Susan Brownell Anthony, 1896 |
Ben Finney

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


Re: Best Practices for Internal Package Structure

2016-04-05 Thread Steven D'Aprano
On Wed, 6 Apr 2016 03:38 am, Sven R. Kunze wrote:

> On 05.04.2016 03:43, Steven D'Aprano wrote:
>> The purpose of packages isn't enable Java-style "one class per file"
>> coding, especially since *everything* in the package except the top level
>> "bidict" module itself is private. bidict.compat and bidict.util aren't
>> flagged as private, but they should be, since there's nothing in either
>> of them that the user of a bidict class should care about.
>>
>> (utils.py does export a couple of functions, but they should be in the
>> main module, or possibly made into a method of BidirectionalMapping.)
>>
>> Your package is currently under 500 lines. As it stands now, you could
>> easily flatten it to a single module:
>>
>> bidict.py
> 
> I don't recommend this.
> 
> The line is blurry but 500 is definitely too much. Those will simply not
> fit on a 1 or 2 generous single screens anymore (which basically is our
> guideline).

Are you serious that you work under the restriction that the entire file
must fit on a single screen? Or at most two pages?

So basically you've moved the burden of scrolling up and down a single file
to find the code you want into searching through the file system to find
the code that you want. I don't see this as an advantage. 


> The intention here is to always have a bit more of a full 
> screen of code (no wasted pixels) while benefiting from switching to
> another file (also seeing a full page of other code).

I don't understand this benefit. How does exceeding 1-2 pages of code in a
file prevent you from opening a second file in a separate window?

As we speak, I have 28 text editor windows open. Not all of them are Python
code, but among those which are, I have:

216 lines
157 lines
906 lines
687 lines
173 lines
373 lines
402 lines
6409 lines
509 lines
97 lines
163 lines
393 lines
1725 lines
25 lines

I have no problem with working with multiple file despite exceeding the
limit, so I don't understand the purpose of this guideline.


-- 
Steven

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


Re: Import graphics error

2016-04-05 Thread Ned Batchelder
On Tuesday, April 5, 2016 at 4:06:02 PM UTC-4, Thomas 'PointedEars' Lahn wrote:
> | >>> from email import ID10T
> | Traceback (most recent call last):
> |   File "", line 1, in 
> | ImportError: cannot import name 'ID10T'

This is uncalled for.  You don't have to participate in this thread if you
don't want to.  This list is part of the Python community, and as such has
adopted the Python CoC: https://www.python.org/psf/codeofconduct/

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


Re: Best Practices for Internal Package Structure

2016-04-05 Thread Steven D'Aprano
On Wed, 6 Apr 2016 04:40 am, Ethan Furman wrote:

> Well, there should be one more module:
> 
>test.py
> 
> So in total, two files
> 
> bidict/
> |-- __init__.py
> |-- test.py


Your test code shouldn't necessarily be part of the package though. If I
already have a package, then I will usually stick the test code inside it,
but if I have a single module, I keep the test code in a separate file and
don't bother installing it. It's there in the source repo for those who
want it.


> will do the trick.  Oh, and you want a README, LICENSE, a doc file.  And
> that should do it.  :)

None of which ought to be part of the package itself. Well, perhaps the
README.



-- 
Steven

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


Re: Best Practices for Internal Package Structure

2016-04-05 Thread Chris Angelico
On Wed, Apr 6, 2016 at 9:29 AM, Steven D'Aprano  wrote:
> As we speak, I have 28 text editor windows open. Not all of them are Python
> code, but among those which are, I have:
> [chomp line number counts]

I was about to say "Wow, I don't have anything LIKE that many text
editor windows open"... but then went and counted. Uhh, 21 tabs up in
SciTE. So, yeah. Same ballpark. Like you, though, some of them aren't
code at all, and of those that are, there's several languages
represented; they range from a fully-functional 19 line file (not
stubby or anything) to a 2026-line module that actually does have some
"maybe X, Y, and Z could be broken out into a separate file" comments.
It's not excessive at the moment, but those few are stretching the
file's stated purpose (they're used primarily by other functions in
the file, though, and there's no better place for them).

Generally, I refactor code not because the files are getting "too
large" (for whatever definition of that term you like), but because
they're stretching the file's concept. Every file should have a
purpose; every piece of code in that file should ideally be supporting
exactly that purpose. This file over here handles the socket
connection to the server - it has functions to connect and disconnect,
to cope with servers that don't declare their encodings, to process
lines of text the server sends and figure out what to do with them, to
manage keep-alives, and so on. That file is all about the GUI - it
creates a window on screen, has event handlers, deals with fonts,
tracks user interaction so it can flag unread information, and has a
small function "connect/disconnect" which handles the UI side of
things and then calls a function from the connection module. One of
these files is 485 lines long; the other is 2026 lines long. Neither
of them needs to be refactored, because they both fit their goals.

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


Re: Best Practices for Internal Package Structure

2016-04-05 Thread Ethan Furman

On 04/05/2016 04:38 PM, Steven D'Aprano wrote:

On Wed, 6 Apr 2016 04:40 am, Ethan Furman wrote:


Well, there should be one more module:

test.py

So in total, two files

bidict/
|-- __init__.py
|-- test.py



Your test code shouldn't necessarily be part of the package though. If I
already have a package, then I will usually stick the test code inside it,
but if I have a single module, I keep the test code in a separate file and
don't bother installing it. It's there in the source repo for those who
want it.



will do the trick.  Oh, and you want a README, LICENSE, a doc file.  And
that should do it.  :)


None of which ought to be part of the package itself. Well, perhaps the
README.


If it's not part of the package, how does it get installed?  And where? 
 (Honest question -- I find the packaging and distribution process 
confusing at best.)


--
~Ethan~

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


Re: python script for .dat file

2016-04-05 Thread Steven D'Aprano
On Wed, 6 Apr 2016 07:49 am, Muhammad Ali wrote:

> Would any one paste here some reference/sample python code for such
> extraction of data into text file?

column1 = ['aa', 'bb', 'cc', 'dd', 'ee', 'ff']  # strings
column2 = [97, 105, 16, 4, 48, 274]  # ints
column3 = [12.345, 7.821, -4.034, 19.034, 23.0, 42.0]  # floats


# Open the file for writing. It will be closed 
# automatically at the end of the block.
with open("myfile.dat", "w") as f:
for t in zip(column1, column2, column3):
line = "%-9s %-9d %-9f\n" % t
print(line, end='')
f.write(line)



The function zip(...) combines one element from each argument into a tuple
of three values, like 

t = ('aa', 97, 12.345)
t = ('bb', 105, 7.821)

etc. The string formatting line:

line = "%-9s %-9d %-9f\n" % t


builds a new string. The code %s takes any object, including strings, and
inserts it into the new string. %d requires an int, and %f requires a
float. The \n at the end inserts a newline.

The -9 inside the formatting codes sets the width and justification:

%-9d

formats an integer in nine columns, justified on the left, while %9d
justifies to the right:


py> print("%-9d." % 23)
23   .
py> print("%9d." % 23)
   23.


Finally, the line is printed so you can see what it looks like, and written
to the file.


-- 
Steven

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


Re: Import graphics error

2016-04-05 Thread Steven D'Aprano
On Wed, 6 Apr 2016 06:05 am, Thomas 'PointedEars' Lahn wrote:


> | >>> from email import ID10T
> | Traceback (most recent call last):
> |   File "", line 1, in 
> | ImportError: cannot import name 'ID10T'
> 
> 


Why oh why can't somebody write "How to write smart answers" for people
like "Pointed Ears"?




-- 
Steven

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


Re: Can't load Tkinter in embedded Python interpreter on Windows

2016-04-05 Thread Kevin Walzer

Adding

 PySys_SetArgv(argc, argv);

did the trick.

--
Kevin Walzer
Code by Kevin/Mobile Code by Kevin
http://www.codebykevin.com
http://www.wtmobilesoftware.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Untrusted code execution

2016-04-05 Thread Steven D'Aprano
On Wed, 6 Apr 2016 03:48 am, Chris Angelico wrote:

> On Wed, Apr 6, 2016 at 3:26 AM, Jon Ribbens
>  wrote:
>> The received wisdom is that restricted code execution in Python is
>> an insolubly hard problem, but it looks a bit like my 7-line example
>> above disproves this theory, 

Jon's 7-line example doesn't come even close to providing restricted code
execution in Python. What it provides is a restricted subset of expression
evaluation, which is *much* easier. It's barely more powerful than the
ast.safe_eval function. That doesn't make it useless, but it does mean that
it's not solving the problem of "restricted code execution".


[Jon again]
>> provided you choose carefully what you 
>> provide in your restricted __builtins__ - but people who knows more
>> than me about Python seem to have thought about this problem for
>> longer than I have and come up with the opposite conclusion so I'm
>> curious what I'm missing.

You're missing that they're trying to allow enough Python functionality to
run useful scripts (not just evaluate a few arithmetic expressions), but
without allowing the script to break out of the restricted environment and
do things which aren't permitted.

For example, check out Tav's admirable work some years ago on trying to
allow Python code to read but not write files:

http://tav.espians.com/a-challenge-to-break-python-security.html

and followups to that post here:

http://tav.espians.com/paving-the-way-to-securing-the-python-interpreter.html
http://tav.espians.com/update-on-securing-the-python-interpreter.html


You should also read Guido's comments on capabilities:

http://neopythonic.blogspot.com.au/2009/03/capabilities-for-python.html

As Zooko says, Guido's "best argument is that reducing usability (in terms
of forbidding language features, especially module import) and reducing the
usefulness of extant library code" would make the resulting interpreter too
feeble to be useful.

Look at what you've done: you've restricted the entire world of Python down
to, effectively, a calculator and a few string methods. That's not to say
that a calculator and a few string methods won't be useful to someone, but
the next Javascript it is not...


[Chris]
> No, it doesn't disprove anything. All you've shown is "here's a piece
> of code that hasn't yet been compromised". :) What you're missing is a
> demonstrated exploit against your code. I can't provide one, but it's
> entirely possible that one will be found.
> 
> Your code is a *lot* safer for using 'eval' rather than 'exec'.
> Otherwise, you'd be easily exploited using exceptions, which carry a
> ton of info. But even so, I would not bet money (much less the
> security of my systems) on this being safe.

I think Jon is on the right approach here for restricting evaluation of
evaluation, which is a nicely constrained and small subset of Python. He's
not allowing unrestricted arbitrary code execution: he has a very
restricted (too restricted -- what the hell can you do with just int, str
and len?) whitelist of functions that are allowed, and the significant
restriction that dunder names aren't allowed.

This makes his function a tiny DSL for calculators and equivalent. I think
that, if it checks out, it would make a good addition to the standard
library.


All the obvious, and even not-so-obvious, attack tools are gone: eval, exec,
getattr, type, __import__. Because you're not supporting Python 2, the
various func.func_* attack surfaces are all gone. Since you can't access
dunders directly, and the obvious indirect methods like eval and getattr
aren't available, I don't think that any of the usual attacks will work.

Keep in mind that Jon's burden is easier: he doesn't need to worry about the
caller's environment, only his own environment. So long as the attacker
can't inject code into his "safe eval" code, the attacker can monkey-patch
their own built-ins and it simply doesn't matter.

(If the attacker can monkey-patch Jon's code, they can do anything they
like.)


I think this approach is promising enough that Jon should take it to a few
other places for comments, to try to get more eyeballs. Stackoverflow and
Reddit's /r/python, perhaps. 

Please do followup here with any results, positive or negative.




-- 
Steven

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


Re: Best Practices for Internal Package Structure

2016-04-05 Thread Steven D'Aprano
On Wed, 6 Apr 2016 05:56 am, Michael Selik wrote:

[Sven R. Kunze]
>> If you work like in the 80's, maybe. Instead of scrolling, (un)setting
>> jumppoints, or use splitview of the same file, it's just faster/easier to
>> jump between separate files in todays IDEs if you need to jump between 4
>> places within 3000 lines of code.

[Michael] 
> When you made that suggestion earlier, I immediately guessed that you were
> using PyCharm. I agree that the decision to split into multiple files or
> keep everything in just a few files seems to be based on your development
> tools. I use IPython and SublimeText, so my personal setup is more suited
> to one or a few files.

How does PyCharm make the use of many files easier?


-- 
Steven

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


Re: Label behavior's difference between tkinter and ttk

2016-04-05 Thread Kevin Walzer
In general, the "img.config" syntax is suitable for the classic Tk 
widgets, not the themed ttk widgets. They have a very different (and 
very gnarly) syntax for indicating changed state. I am not inclined to 
see a bug here.


--
Kevin Walzer
Code by Kevin/Mobile Code by Kevin
http://www.codebykevin.com
http://www.wtmobilesoftware.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: Best Practices for Internal Package Structure

2016-04-05 Thread Steven D'Aprano
On Wed, 6 Apr 2016 09:54 am, Ethan Furman wrote:

> On 04/05/2016 04:38 PM, Steven D'Aprano wrote:
>> On Wed, 6 Apr 2016 04:40 am, Ethan Furman wrote:
>>
>>> Well, there should be one more module:
>>>
>>> test.py
>>>
>>> So in total, two files
>>>
>>> bidict/
>>> |-- __init__.py
>>> |-- test.py
>>
>>
>> Your test code shouldn't necessarily be part of the package though. If I
>> already have a package, then I will usually stick the test code inside
>> it, but if I have a single module, I keep the test code in a separate
>> file and don't bother installing it. It's there in the source repo for
>> those who want it.
>>
>>
>>> will do the trick.  Oh, and you want a README, LICENSE, a doc file.  And
>>> that should do it.  :)
>>
>> None of which ought to be part of the package itself. Well, perhaps the
>> README.
> 
> If it's not part of the package, how does it get installed?  And where?
>   (Honest question -- I find the packaging and distribution process
> confusing at best.)

Why do they need to be installed? They're part of the development
environment, not the module.

(Actually, I take it back about the README, since conventionally that's used
to give installation instructions. Once the module is installed, you don't
usually need the README any more. But the doc file might be more useful.)


I don't know what life is like in the brave new world of wheels, eggs, pip
and other new-fangled complications^W tools, but in the good old fashioned
setuptools world, you have something like a zip file or tarball that
contains your code, plus an installation script. The contents of the zip
file will be something like this, taken from PyParsing version 2.1.1:


build/
CHANGES
dist/
docs/
examples/
htmldoc/
HowToUsePyparsing.html
LICENSE
MANIFEST.in
PKG-INFO
pyparsingClassDiagram.JPG
pyparsingClassDiagram.PNG
README
pyparsing.egg-info/
pyparsing.py
robots.txt
setup.cfg
setup.py

You unzip the file, cd into that directory and run:

python setup.py install

which then magically installs the module somewhere that just works. In this
specific case, it installs the module in a file

/usr/local/lib/python3.3/site-packages/pyparsing-2.1.1-py3.3.egg

which happens to be a vanilla zip file containing the pyparsing.py file, a
byte-code compiled .pyc version, and a directory EGG-INFO that presumably
allows pip or whatever to uninstall it again, or something, who the hell
knows how this works.

But the installer could just have easily have just installed the
pyparsing.py file alone.

The point is, the tests, documentation, etc aren't necessarily part of the
module, so they don't necessarily need to be installed into your
site-packages. If the user wants to read the HTML docs, they can browse
into the expanded source tarball and read them there, or drag the docs into
their home directory, or whatever they feel like. If they want to run the
tests, they run them from the source directory, not site-packages.

Of course, if you prefer to keep the tests inside the package, that's up to
you. But you needn't feel that this is the best or only place for them.



-- 
Steven

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


Re: Import graphics error

2016-04-05 Thread Steven D'Aprano
Since Dennis has X-No-Archive set on his posts, his very useful answer to
Nicolae will be lost in a matter of days.

So I'm going to repeat it.

Nicolae, Dennis found the fix is to change the example code. 

Read the documentation here:

http://mcsp.wartburg.edu/zelle/python/graphics/graphics.pdf

Download and install this file:

http://mcsp.wartburg.edu/zelle/python/graphics.py

Change the example to this:


import graphics as g
win = g.GraphWin()
rect = g.Rectangle(g.Point(5, 10), g.Point(20, 30))
rect.draw(win)
win.getMouse()


which should run now. Thanks Dennis for your hard work identifying this!


Dennis has more comments as well which you should read, quoted below.


On Wed, 6 Apr 2016 12:01 pm, Dennis Lee Bieber wrote:

> On Tue, 5 Apr 2016 17:17:54 +0100, Nicolae Morkov
>  declaimed the following:
> 
>>I copied the code from Python from everyone page 67.
> 
> Which edition? There is now a second edition out (and I don't intend to
> pay $70 for it just to assist a simple question)
> 
>>Following the instructions The graphic modules by John Zelle I copied 
>>into the python lacation ,to be easier to find the path .
>>
> Which version? Did you also download the documentation (it runs around
> 6 pages) for the library. The odds are very good that the library (v4 as I
> recall) may have changed a lot from when a 1st edition book was written.
> 
> Just downloaded
> http://mcsp.wartburg.edu/zelle/python/graphics.py
> and copied it into my Python installation Lib\site-packages directory
> (actually -- all four, since I have Python 2.7 and [old] 3.3 in both 32
> and 64 bit variants on the machine).
> 
> Using
> http://mcsp.wartburg.edu/zelle/python/graphics/graphics.pdf
> as a guide, I converted your example into
> 
> -=-=-=-
> 
> import graphics as g
> 
> win = g.GraphWin()
> rect = g.Rectangle(g.Point(5, 10), g.Point(20, 30))
> rect.draw(win)
> win.getMouse()
> -=-=-=-
> 
> It runs!
> 
> Note that the current version of that library is fully object-based --
> the rectange is defined by two corners which are represented by a pair of
> Point objects -- and after the rectangle object has been created, one has
> to tell /it/ to draw itself on the specified window. The getMouse() call
> holds the program until you click the mouse in the window (technically it
> returns a Point with the coordinates, but I'm throwing it away)




-- 
Steven

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


  1   2   >