__bases__ attribute on classes not displayed by dir() command

2016-02-04 Thread ast

Hi

I have a Carre class which inherit from a Rectangle class.
Carre has a __bases__ tuple attribute which contains the
classes which it inherit from.


Carre.__bases__

(,)

and Rectangle only inherit from object, so:


Rectangle.__bases__

(,)

Thats OK

but if I am using dir to display all Carre's attributes and methods,
__bases__ is not on the list. Why ?


dir(Carre)

['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__',
'__format__', '__ge__', '__getattribute__', '__gt__', '__hash__',
'__init__', '__iter__', '__le__', '__lt__', '__module__', '__ne__',
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', 
'__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'aire', 
'count', 'long', 'perimetre', 'rotation']



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


Finding in which class an object's method comes from

2016-02-04 Thread ast

Hi

Suppose we have:

ClassC inherit from ClassB
ClassB inherit from ClassA
ClassA inherit from object

Let's build an object:

obj = ClassC()

Let's invoke an obj method

obj.funct()

funct is first looked in ClassC, then if not found
on ClassB, then ClassA then object

But is there a command to know where funct is
found ?

Thx




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


Re: Finding in which class an object's method comes from

2016-02-04 Thread Chris Angelico
On Thu, Feb 4, 2016 at 7:25 PM, ast  wrote:
> Hi
>
> Suppose we have:
>
> ClassC inherit from ClassB
> ClassB inherit from ClassA
> ClassA inherit from object
>
> Let's build an object:
>
> obj = ClassC()
>
> Let's invoke an obj method
>
> obj.funct()
>
> funct is first looked in ClassC, then if not found
> on ClassB, then ClassA then object
>
> But is there a command to know where funct is
> found ?

You can see that by looking at the objects without calling them:

>>> class A:
...  def a(self): pass
...
>>> class B(A):
...  def b(self): pass
...
>>> class C(B):
...  def c(self): pass
...
>>> obj = C()
>>> obj.a
>
>>> obj.b
>
>>> obj.c
>

The information comes from the function's qualname:

>>> obj.c.__func__.__qualname__
'C.c'

Is that what you're hoping for?

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


Install Error

2016-02-04 Thread Barrie Taylor
Hi,

I am attempting to install and run Python3.5.1 on my Windows machine.

After installation on launching I am presented the attached error message.
It reads:
'The program can't start because api-ms-win-crt-runtime-l1-1-0.dll is missing 
from your computer. Try reinstalling the program to fix this problem.'
Needless to say, I have tried uninstalling and reinstalling ad repairing the 
program a number of times to no avail.

Any help with this issue would be greatly appreciated.

Kind Regards,

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


please help

2016-02-04 Thread Syavosh Malek
hi i install python 3.5.1 and found run time error
see attach file and help me please
-- 
https://mail.python.org/mailman/listinfo/python-list


import cannot be used inside eval

2016-02-04 Thread 阎兆珣
   a = input("tell me which py to execute:  ")

   print(a)

   print('import '+a)

   print(type('import'+a))

   eval('print(a)')

   try:

       eval('import '+a)

   except Exception as e:

       print('Error: ', e)

   ##while True:

   ##    pass

   @python 3.4.2

   this code attempts to run a .py file that user specifies.

   eval() does fine with print() command

   but fails to call import command

   Is it a but or a taboo?

   Thanks

   Zhaoxun Yan          

   Option Product Manager

   Gelin Dahua Futures Co.Ltd

    T: +86 10 56711783
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Finding in which class an object's method comes from

2016-02-04 Thread ast


"Chris Angelico"  a écrit dans le message de 
news:[email protected]...


Is that what you're hoping for?



yes, ty 


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


Re: import cannot be used inside eval

2016-02-04 Thread Chris Angelico
On Thu, Feb 4, 2016 at 4:03 PM, 阎兆珣  wrote:
>a = input("tell me which py to execute:  ")
>
>print(a)
>
>print('import '+a)
>
>print(type('import'+a))
>
>eval('print(a)')
>
>try:
>
>eval('import '+a)
>
>except Exception as e:
>
>print('Error: ', e)
>
>##while True:
>
>##pass
>
>@python 3.4.2
>
>this code attempts to run a .py file that user specifies.
>
>eval() does fine with print() command
>
>but fails to call import command

The eval() function evaluates an expression. It won't handle
statements (if, for, while), and import is a statement. Possibly you
want exec instead.

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


Re: Finding in which class an object's method comes from

2016-02-04 Thread Ben Finney
"ast"  writes:

> Let's invoke an obj method
>
> obj.funct()
>
> funct is first looked in ClassC, then if not found
> on ClassB, then ClassA then object

If it helps: What you describe is attribute lookup, and it happens
whether or not you're going to call the attribute.

In other words, you need only invoke ‘foo.attr’ to have Python look for
attribute ‘attr’ among the class hierarchy as you describe. Calling that
attribute is a distinct operation once the attribute is found.

> But is there a command to know where funct is found ?

That's been answered, but I'm curious to know what your program will do
with that information?

-- 
 \   “But Marge, what if we chose the wrong religion? Each week we |
  `\  just make God madder and madder.” —Homer, _The Simpsons_ |
_o__)  |
Ben Finney

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


Re: Finding in which class an object's method comes from

2016-02-04 Thread ast


"Chris Angelico"  a écrit dans le message de 
news:[email protected]...



You can see that by looking at the objects without calling them:


class A:

...  def a(self): pass
...

class B(A):

...  def b(self): pass
...

class C(B):

...  def c(self): pass
...

obj = C()
obj.a

>

obj.b

>

obj.c

>

The information comes from the function's qualname:


obj.c.__func__.__qualname__

'C.c'

Is that what you're hoping for?



It is strange but I dont have the same result that you:
(Python 3.4)


class A:

def a(self):pass

>>> class B(A):
def b(self):pass

>>> class C(B):
def c(self):pass

>>> obj = C()


obj.a

>

But with __qualname__ it works


obj.a.__func__.__qualname__

'A.a'


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


Re: __bases__ attribute on classes not displayed by dir() command

2016-02-04 Thread eryk sun
On Thu, Feb 4, 2016 at 2:03 AM, ast  wrote:
> but if I am using dir to display all Carre's attributes and methods,
> __bases__ is not on the list. Why ?

The __bases__ property is defined by the metaclass, "type". dir() of a
class doesn't show attributes from the metaclass [1].

Because dir() is supplied primarily as a convenience for use at an
interactive prompt, it tries to supply an interesting set of names
more than it tries to supply a rigorously or consistently defined set
of names, and its detailed behavior may change across releases.
For example, metaclass attributes are not in the result list when
the argument is a class.

To see the metaclass attributes use dir(type(Carre)).

[1]: https://docs.python.org/3/library/functions.html#dir
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Finding in which class an object's method comes from

2016-02-04 Thread ast


"Ben Finney"  a écrit dans le message de 
news:[email protected]...




That's been answered, but I'm curious to know what your program will do
with that information?



Nothings, I was just wondering. 


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


Re: Finding in which class an object's method comes from

2016-02-04 Thread Chris Angelico
On Thu, Feb 4, 2016 at 7:54 PM, ast  wrote:
> It is strange but I dont have the same result that you:
> (Python 3.4)
>
 class A:
>
> def a(self):pass
>
 class B(A):
> def b(self):pass
>
 class C(B):
> def c(self):pass
>
 obj = C()
>
 obj.a
>
> >

Curious. It appears to have changed between 3.4 and 3.5; my original
copy/paste was from 3.6.

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


Re: import cannot be used inside eval

2016-02-04 Thread Gary Herron

On 02/03/2016 09:03 PM, 阎兆珣 wrote:

a = input("tell me which py to execute:  ")

print(a)

print('import '+a)

print(type('import'+a))

eval('print(a)')
Eval is meant to evaluate Python expressions.  The import is a 
statement, not an expression.  Also, it's a bad idea to use eval like 
this, and it's a *really* bad idea to use eval with user supplied 
input.  The user could inject *any* malicious code.


Instead, use the importlib module to programmatically import a module.

Gary Herron


--
Dr. Gary Herron
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418


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


Re: __bases__ attribute on classes not displayed by dir() command

2016-02-04 Thread ast


"eryk sun"  a écrit dans le message de 
news:[email protected]...

On Thu, Feb 4, 2016 at 2:03 AM, ast  wrote:

but if I am using dir to display all Carre's attributes and methods,
__bases__ is not on the list. Why ?


The __bases__ property is defined by the metaclass, "type". dir() of a
class doesn't show attributes from the metaclass [1].



Oh metaclass !

I am learning them at the moment, and have headaches 


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


Re: Install Error

2016-02-04 Thread Oscar Benjamin
On 3 February 2016 at 21:55, Barrie Taylor  wrote:
>
> I am attempting to install and run Python3.5.1 on my Windows machine.
>
> After installation on launching I am presented the attached error message.
> It reads:
> 'The program can't start because api-ms-win-crt-runtime-l1-1-0.dll is missing 
> from your computer. Try reinstalling the program to fix this problem.'
> Needless to say, I have tried uninstalling and reinstalling ad repairing the 
> program a number of times to no avail.

I don't know why it says to try re-installing. The problem is that
Python 3.5 requires an update to your system runtimes from Microsoft.
You can find more information about that here:

https://support.microsoft.com/en-us/kb/2999226

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


Re: please help

2016-02-04 Thread Oscar Benjamin
On 3 February 2016 at 23:03, Syavosh Malek  wrote:
> hi i install python 3.5.1 and found run time error
> see attach file and help me please

I'm afraid your attachment didn't arrive as this is a text-only
mailing list. Can you include more information about the error?

If it's that you're missing a dll called something like
Api-ms-win-crt-runtime-l1-1-0.dll then you need to update your system
runtimes from Microsoft. You can read about that here:
https://support.microsoft.com/en-us/kb/2999226

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


How this C function was called through ctypes this way?

2016-02-04 Thread jfong
Here is an example from "Python Cookbook, Third Edition(by David Beazley and 
Brian K. Jones)" Chapter 15.1. "Accessing C Code Using ctypes"

---
import ctypes
...
# Try to locate the .so file in the same directory as this file
...
_mod = ctypes.cdll.LoadLibrary(_path)
...
...
# void avg(double *, int n)
# Define a special type for the 'double *' argument
class DoubleArrayType:
def from_param(self, param):
typename = type(param).__name__
if hasattr(self, 'from_' + typename):
return getattr(self, 'from_' + typename)(param)
elif isinstance(param, ctypes.Array):
return param
else:
raise TypeError("Can't convert %s" % typename)

...
# Cast from array.array objects
def from_array(self, param):
...
...

# Cast from lists
def from_list(self, param):
val = ((ctypes.c_double)*len(param))(*param)
return val

# Cast from a numpy array
def from_ndarray(self, param):
...
...

DoubleArray = DoubleArrayType()
_avg = _mod.avg
_avg.argtypes = (DoubleArray, ctypes.c_int)
_avg.restype = ctypes.c_double

def avg(values):
return _avg(values, len(values))

avg([1,2,3])
--

The followings was quoted from the book which explain how it does:
"The DoubleArrayType class shows how to handle this situation. In this class, a 
single method from_param() is defined. The role of this method is to take a 
single parameter and narrow it down to a compatible ctypes object (a pointer to 
a ctypes.c_double, in the example). Within from_param(), you are free to do 
anything that you wish. In the solution, the typename of the parameter is 
extracted and used to dispatch to a more specialized method. For example, if a 
list is passed, the typename is list and a method from_list() is invoked."

What confuse me are:
(1) at line: _avg.argtypes = (DoubleArray, ctypes.c_int)
The "DoubleArry" is an instance of the class "DoubleArrayType", Can it appear 
at where a type was expected? 
(2) How the method "from_param" was invoked? I can't see any mechanism to reach 
it from the "_avg(values, len(values))" call.


Best Regards,
Jach Fong

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


Re: Finding in which class an object's method comes from

2016-02-04 Thread Wolfgang Maier

On 04.02.2016 10:00, Chris Angelico wrote:

On Thu, Feb 4, 2016 at 7:54 PM, ast  wrote:

It is strange but I dont have the same result that you:
(Python 3.4)


class A:


def a(self):pass


class B(A):

def b(self):pass


class C(B):

def c(self):pass


obj = C()



obj.a


>


Curious. It appears to have changed between 3.4 and 3.5; my original
copy/paste was from 3.6.



I think http://bugs.python.org/issue21389 causes the difference. I think 
the change was introduced with Python3.5.



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


Multiprocess videoplayer

2016-02-04 Thread mdelamo90
I have coded a program with python and vlc that plays some videos, but whenever 
I try to play 3 videos at once, Windows closes the program, I'm guessing that 
the reason is that one process can't play 3 videos at once (but I don't really 
know).

My trimmed program plays one video (trhough a global variable, os it's easy to 
change) and once you press the number 2 on the keyboard it put the data from a 
video on the queue to be played by another process.

The new process starts and makes some prints, then it should start the new 
video and another one, so we should have two videos playing, one on the left 
part of the screen and the other on the right. 

I've done this on linear programming, but I can't make the new process to start 
the videos. I oame from a C/C++ background so I don't know if it's something I 
didn't fully grasp about the multiprocess on Python or something else that I'm 
doing wrong.

Its huge for a miniexample (300 lines), but I didn't know how to make it 
shorter:


# import external libraries
import wx # 2.8
import vlc
import pdb
# import standard libraries
import user
import urllib
import multiprocessing



VIDEO1 = "Insert_your_first_video.mp4"
VIDEO2 = "Insert_your_second_video.mp4"

class MyOpener(urllib.FancyURLopener):
version = "App/1.7"  # doesn't work
version = "Mozilla/4.0 (MSIE 6.0; Windows NT 5.0)2011-03-10 15:38:34"  # 
works


class Consumer(multiprocessing.Process):
def __init__(self, task_queue):
multiprocessing.Process.__init__(self)
self.task_queue = task_queue

def run(self):
app = wx.App()
proc_name = self.name

print "waiting for queue"

while True:  # While queue not empy
print self.task_queue.qsize()
next_task = self.task_queue.get()
global dual, midsection
dual = True
midsection = next_task.d
player2 = Player("Dual PyVLC Player")
player2.Centre()
# show the player window centred and run the application
print "parametro a " + str(next_task.a)
print "parametro b " + str(next_task.b)
print "parametro c " + str(next_task.c)
print "parametro d " + str(next_task.d)
  # tasks.put(Task(media, dual, time, midsection))

player2.playFile(next_task.a,next_task.c,True)
player2.playFile(VIDEO2,next_task.c,True)
#player.vidplayer1.set_media(next_task.a)
#player.vidplayer2.play()
player2.Maximize(True)
player2.OnFullscreen(None)
player2.SetTransparent(255)
player2.SetFocus()
player2.Show()
#player2.vidplayer1.set_title(next_task.a)
'''player1.SetTransparent(0)
player1.timer1.Start(fadetime)
player1.set_amount(0)'''

def playFile(self,moviefile,time,principal):

# Creation
self.Media = self.Instance.media_new_path(moviefile)
self.SetTitle("Monkey")
#self.SetIcon(wx.Icon('Monkey.ico', wx.BITMAP_TYPE_ICO))

if dual:
if principal:
#If we dont set any handle it starts in another window, maybe 
usefull for dual screens?
self.vidplayer1.set_media(self.Media)
#self.vlchandle = self.vidplayer1.get_xwindow()
self.vidplayer1.set_hwnd(self.videopanel.GetHandle())
self.OnPlay(None,True)
self.vidplayer1.set_time(time)
else:
self.vidplayer2.set_media(self.Media)
#self.vlchandle = self.vidplayer2.get_xwindow()
self.vidplayer2.set_hwnd(self.videopanel2.GetHandle())
self.OnPlay(None,False)
self.vidplayer2.set_time(time)
else:
self.vidplayer1.set_media(self.Media)
#self.vlchandle = self.vidplayer1.get_xwindow()
self.vidplayer1.set_hwnd(self.videopanel.GetHandle())
self.OnPlay(None,True)
self.vidplayer1.set_time(time)

class Task(object):
def __init__(self, a, b, c, d):
self.a = a  # can't be media, it's not pickable
self.b = b  # boolean
self.c = c  # Number (time)
self.d = d  # boolean

def __str__(self):
return '%s * %s' % (self.a, self.b, self.c, self.d)

class Player(wx.Frame):
"""The main window has to deal with events.
"""
def __init__(self, title, OS="windows"):

self.OS = OS

wx.Frame.__init__(self, None, -1, title,
  pos=wx.DefaultPosition, size=(950, 500))
self.SetBackgroundColour(wx.BLACK)

# Panels
# The first panel holds the video/videos and it's all black

self.videopanel = wx.Panel(self, -1)
self.videopanel.SetBackgroundStyle(wx.BG_STYLE_COLOUR)
self.videopanel.SetBackgroundColour(wx.BLACK)

if dual:
videopanel2 = wx.Panel(self, -1)
  

How a module is being marked as imported?

2016-02-04 Thread Jean-Charles Lefebvre
Hi all,

The short version: How CPython marks a module as being fully imported, if it 
does, so that the same import statement ran from another C thread at the same 
time does not collide? Or, reversely, does not think the module is not already 
fully imported?

The full version: I'm running CPython 3.5.1, embedded into a C++ application on 
Windows. The application is heavily multi-threaded so several C threads call 
some Python code at the same time (different Python modules), sharing 
interpreter's resources by acquiring/releasing the GIL frequently DURING the 
calls, at language boundaries.

Sometimes (but always only once per application instance), a call to 
os.path.expandvars raises the AttributeError exception with message: module 
'string' has no attribute 'ascii_letters'. It is raised by the 
ntpath.expandvars function (line 372). When I noticed the late import statement 
of the 'string' module at the line above, I thought that MAYBE, it could be 
because the interpreter is ran in an heavily multi-threaded environment and 
that the GIL acquiring/releasing occurred at a bad timing? Making me wonder how 
the import mechanism interacts with the GIL, if it does?
-- 
https://mail.python.org/mailman/listinfo/python-list


multiprocessing videoplayer

2016-02-04 Thread mdelamo90
I have coded a program with python and vlc that plays some videos, but whenever 
I try to play 3 videos at once, Windows closes the program, I'm guessing that 
the reason is that one process can't play 3 videos at once (but I don't really 
know).

My trimmed program plays one video (trhough a global variable, os it's easy to 
change) and once you press the number 2 on the keyboard it put the data from a 
video on the queue to be played by another process.

The new process starts and makes some prints, then it should start the new 
video and another one, so we should have two videos playing, one on the left 
part of the screen and the other on the right.

I've done this on linear programming, but I can't make the new process to start 
the videos. I oame from a C/C++ background so I don't know if it's something I 
didn't fully grasp about the multiprocess on Python or something else that I'm 
doing wrong.

Its huge for a miniexample (300 lines), but I didn't know how to make it 
shorter:


# import external libraries
import wx # 2.8
import vlc
import pdb
# import standard libraries
import user
import urllib
import multiprocessing



VIDEO1 = "Insert_your_first_video.mp4"
VIDEO2 = "Insert_your_second_video.mp4"

class MyOpener(urllib.FancyURLopener):
version = "App/1.7"  # doesn't work
version = "Mozilla/4.0 (MSIE 6.0; Windows NT 5.0)2011-03-10 15:38:34"  # 
works


class Consumer(multiprocessing.Process):
def __init__(self, task_queue):
multiprocessing.Process.__init__(self)
self.task_queue = task_queue

def run(self):
app = wx.App()
proc_name = self.name

print "waiting for queue"

while True:  # While queue not empy
print self.task_queue.qsize()
next_task = self.task_queue.get()
global dual, midsection
dual = True
midsection = next_task.d
player2 = Player("Dual PyVLC Player")
player2.Centre()
# show the player window centred and run the application
print "parametro a " + str(next_task.a)
print "parametro b " + str(next_task.b)
print "parametro c " + str(next_task.c)
print "parametro d " + str(next_task.d)
  # tasks.put(Task(media, dual, time, midsection))

player2.playFile(next_task.a,next_task.c,True)
player2.playFile(VIDEO2,next_task.c,False)
#player.vidplayer1.set_media(next_task.a)
#player.vidplayer2.play()
player2.Maximize(True)
player2.OnFullscreen(None)
player2.SetTransparent(255)
player2.SetFocus()
player2.Show()
#player2.vidplayer1.set_title(next_task.a)
'''player1.SetTransparent(0)
player1.timer1.Start(fadetime)
player1.set_amount(0)'''

def playFile(self,moviefile,time,principal):

# Creation
self.Media = self.Instance.media_new_path(moviefile)
self.SetTitle("Monkey")
#self.SetIcon(wx.Icon('Monkey.ico', wx.BITMAP_TYPE_ICO))

if dual:
if principal:
#If we dont set any handle it starts in another window, maybe 
usefull for dual screens?
self.vidplayer1.set_media(self.Media)
#self.vlchandle = self.vidplayer1.get_xwindow()
self.vidplayer1.set_hwnd(self.videopanel.GetHandle())
self.OnPlay(None,True)
self.vidplayer1.set_time(time)
else:
self.vidplayer2.set_media(self.Media)
#self.vlchandle = self.vidplayer2.get_xwindow()
self.vidplayer2.set_hwnd(self.videopanel2.GetHandle())
self.OnPlay(None,False)
self.vidplayer2.set_time(time)
else:
self.vidplayer1.set_media(self.Media)
#self.vlchandle = self.vidplayer1.get_xwindow()
self.vidplayer1.set_hwnd(self.videopanel.GetHandle())
self.OnPlay(None,True)
self.vidplayer1.set_time(time)

class Task(object):
def __init__(self, a, b, c, d):
self.a = a  # can't be media, it's not pickable
self.b = b  # boolean
self.c = c  # Number (time)
self.d = d  # boolean

def __str__(self):
return '%s * %s' % (self.a, self.b, self.c, self.d)

class Player(wx.Frame):
"""The main window has to deal with events.
"""
def __init__(self, title, OS="windows"):

self.OS = OS

wx.Frame.__init__(self, None, -1, title,
  pos=wx.DefaultPosition, size=(950, 500))
self.SetBackgroundColour(wx.BLACK)

# Panels
# The first panel holds the video/videos and it's all black

self.videopanel = wx.Panel(self, -1)
self.videopanel.SetBackgroundStyle(wx.BG_STYLE_COLOUR)
self.videopanel.SetBackgroundColour(wx.BLACK)

if dual:
videopanel2 = wx.Panel(self, -1)
  

Re: How this C function was called through ctypes this way?

2016-02-04 Thread eryk sun
On Thu, Feb 4, 2016 at 3:33 AM,   wrote:
>
> class DoubleArrayType:
> def from_param(self, param):
>
> [snip]
>
> DoubleArray = DoubleArrayType()
> _avg = _mod.avg
> _avg.argtypes = (DoubleArray, ctypes.c_int)
>
> [snip]
>
> What confuse me are:
> (1) at line: _avg.argtypes = (DoubleArray, ctypes.c_int)
> The "DoubleArry" is an instance of the class "DoubleArrayType",
> Can it appear at where a type was expected?

ctypes generally (notwithstanding out parameters defined via
paramflags) requires only that an object set in argtypes has a
from_param callable to check and convert the corresponding argument.
Usually classes are set in argtypes, so usually from_param is a
classmethod. In this case the author chose to set an instance in
argtypes and use an instance method. While unusual, this works all the
same.

> (2) How the method "from_param" was invoked? I can't see any
> mechanism to reach it from the "_avg(values, len(values))" call.

A ctypes function pointer is a callable implemented in C. Its tp_call
slot function is PyCFuncPtr in Modules/_ctypes/_ctypes.c, which in
turn calls _ctypes_callproc in Modules/_ctypes/callproc.c. Here's the
snippet of code from _ctypes_callproc that's responsible for calling
the from_param converter:

converter = PyTuple_GET_ITEM(argtypes, i);
v = PyObject_CallFunctionObjArgs(converter, arg, NULL);

Note that "argtypes" in the above is a misnomer; it's actually the
tuple of from_param converters.

Each from_param return value is passed to ConvParam, which handles
ctypes objects, integers, strings, and None. If the object isn't of
those but has an _as_parameter_ attribute, ConvParam calls itself
recursively using the _as_parameter_ value.

> _mod = ctypes.cdll.LoadLibrary(_path)

Calling ctypes.CDLL directly is preferable since it allows passing
parameters such as "mode" and "use_errno".

IMO, the ctypes.cdll and ctypes.windll loaders should be avoided in
general, especially on Windows, since their attribute-based access
(e.g. windll.user32) caches libraries, which in turn cache
function-pointer attributes. You don't want function pointer instances
being shared across unrelated packages. They may not use compatible
prototypes and errcheck functions. Each package, module, or script
should create private instances of CDLL, PyDLL, and WinDLL for a given
shared library.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: problem in installing python

2016-02-04 Thread Salony Permanand
hello sir,
During working on python I need urllib2 for my python version 2.7.11.
Kindly provide me address from where to download it..
Thanking you.

On Wed, Feb 3, 2016 at 4:27 PM, Salony Permanand  wrote:

> Thankyou for consideration..I have solved my problem by changing name of
> temp files by "temp1"
>
> -- Forwarded message --
> From: eryk sun 
> Date: Wed, Feb 3, 2016 at 3:55 PM
> Subject: Re: problem in installing python
> To: [email protected]
> Cc: Salony Permanand 
>
>
> On Wed, Feb 3, 2016 at 12:57 AM, Salony Permanand
>  wrote:
> >
> > I downloaded different version of python but no one is installed on my pc
> > because of same installation error each time having error code 2203.
>
> 2203 may be a Windows Installer error [1]. If so, the error message
> has the following template:
>
> Database: [2]. Cannot open database file. System error [3].
>
> Please provide the "System error", since it may help to determine why
> the installer can't open the file. Possibly an anti-virus program is
> interfering, in which case temporarily disabling it may solve the
> problem.
>
> [1]: https://msdn.microsoft.com/en-us/library/aa372835
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Non working Parallel videoplayer

2016-02-04 Thread mdelamo90
I have coded a program with python and vlc that plays some videos, but whenever 
I try to play 3 videos at once, Windows closes the program, I'm guessing that 
the reason is that one process can't play 3 videos at once (but I don't really 
know).

My trimmed program plays one video (trhough a global variable, os it's easy to 
change) and once you press the number 2 on the keyboard it put the data from a 
video on the queue to be played by another process.

The new process starts and makes some prints, then it should start the new 
video and another one, so we should have two videos playing, one on the left 
part of the screen and the other on the right.

I've done this on linear programming, but I can't make the new process to start 
the videos. I oame from a C/C++ background so I don't know if it's something I 
didn't fully grasp about the multiprocess on Python or something else that I'm 
doing wrong.

Here is the linear working version (commented lines 206-220) and the parallel 
non-working version lines (221-225) Comment/Uncomment to toogle bewtween them.

Its huge for a miniexample (383 lines), but I didn't know how to make it 
shorter (it comes from a 3000+ project):



# import external libraries
import wx # 2.8
import vlc
import pdb
from time import sleep
# import standard libraries
import user
import urllib

VIDEO1 = "Insert_your_first_video.mp4"
VIDEO2 = "Insert_your_second_video.mp4"


class MyOpener(urllib.FancyURLopener):
version = "App/1.7"  # doesn't work
version = "Mozilla/4.0 (MSIE 6.0; Windows NT 5.0)2011-03-10 15:38:34"  # 
works


class Consumer(multiprocessing.Process):
def __init__(self, task_queue):
multiprocessing.Process.__init__(self)
self.task_queue = task_queue

def run(self):
app = wx.App()
proc_name = self.name

print "waiting for queue"

while True:  # While queue not empy
print self.task_queue.qsize()
next_task = self.task_queue.get()
global dual, midsection
midsection = next_task.d
dual = True
player2 = Player("Dual PyVLC Player")
player2.Centre()
# show the player window centred and run the application
print "parametro a " + str(next_task.a)
print "parametro b " + str(next_task.b)
print "parametro c " + str(next_task.c)
print "parametro d " + str(next_task.d)
  # tasks.put(Task(media, dual, time, midsection))

player2.playFile(VIDEO1,next_task.c,True)
player2.playFile(VIDEO2,next_task.c,False)
#player.vidplayer1.set_media(next_task.a)
#player.vidplayer2.play()
player2.Maximize(True)
player2.OnFullscreen(None)
player2.SetTransparent(255)
player2.SetFocus()
player2.Show(True)
#sleep(1)
#player2.vidplayer1.set_title(next_task.a)
'''player1.SetTransparent(0)
player1.timer1.Start(fadetime)
player1.set_amount(0)'''

def playFile(self,moviefile,time,principal):

# Creation
self.Media = self.Instance.media_new_path(moviefile)
self.SetTitle("Monkey")
#self.SetIcon(wx.Icon('Monkey.ico', wx.BITMAP_TYPE_ICO))

if dual:
if principal:
#If we dont set any handle it starts in another window, maybe 
usefull for dual screens?
self.vidplayer1.set_media(self.Media)
#self.vlchandle = self.vidplayer1.get_xwindow()
self.vidplayer1.set_hwnd(self.videopanel.GetHandle())
self.OnPlay(None,True)
self.vidplayer1.set_time(time)
else:
self.vidplayer2.set_media(self.Media)
#self.vlchandle = self.vidplayer2.get_xwindow()
self.vidplayer2.set_hwnd(self.videopanel2.GetHandle())
self.OnPlay(None,False)
self.vidplayer2.set_time(time)
else:
self.vidplayer1.set_media(self.Media)
#self.vlchandle = self.vidplayer1.get_xwindow()
self.vidplayer1.set_hwnd(self.videopanel.GetHandle())
self.OnPlay(None,True)
self.vidplayer1.set_time(time)

class Task(object):
def __init__(self, a, b, c, d):
self.a = a  # can't be media, it's not pickable
self.b = b  # boolean
self.c = c  # Number (time)
self.d = d  # boolean

def __str__(self):
return '%s * %s' % (self.a, self.b, self.c, self.d)

class Player(wx.Frame):
"""The main window has to deal with events.
"""
def __init__(self, title, OS="windows"):

self.OS = OS

wx.Frame.__init__(self, None, -1, title,
  pos=wx.DefaultPosition, size=(950, 500))
self.SetBackgroundColour(wx.BLACK)

# Panels
# The first panel holds the video/videos and it's all black

self.videop

Re: Non working Parallel videoplayer

2016-02-04 Thread mdelamo90
I think it has to be with some functions that I think they are defined on the 
"forked" processes and maybe they don't, if I create a class on the new process 
it should have all the defined functions than the original right?
-- 
https://mail.python.org/mailman/listinfo/python-list


setup failed

2016-02-04 Thread Prince Thomas
Hi

   I am an computer science engineer. I downloaded the python version 
3.5.1.amd64 and just python 3.5.1. The problem is when I install the program 
setup is failed and showing  0*80070570-The file or directory is corrupted and 
unreadable. I install the newest visual c++ redist and still same. My os is win 
8.1. Please help me out of this 






Sent from Windows Mail
-- 
https://mail.python.org/mailman/listinfo/python-list


.py file won't open in windows 7

2016-02-04 Thread Yossifoff Yossif
Hallow,
I try to open a .py file (attached), but what I get is a windows DOS window 
opening and closing in a couple of seconds. Ran repair of the program, nothing 
happened.
I cannot see error messages and don't know where to look for ones.
Would appreciate your piece of advice.

[cid:[email protected]]



joseph

Yossif Yossifoff

Operations CS Core

Hot Mobile

Office +972539036945,

Mobile +972532422649

[email protected]





















This message (including any attachments) is intended only for the use of the 
individual or entity to which it is addressed and may contain materials 
protected by copyright or information that is non-public, proprietary, 
privileged, confidential, and exempt from disclosure under applicable law or 
agreement. If you are not the intended recipient, you are hereby notified that 
any use, dissemination, distribution, or copying of this communication is 
strictly prohibited. If you have received this communication by error, notify 
the sender immediately and delete this message immediately. Thank you
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: .py file won't open in windows 7

2016-02-04 Thread Tim Golden
On 04/02/2016 12:52, Yossifoff Yossif wrote:
> Hallow,
> I try to open a .py file (attached), but what I get is a windows DOS window 
> opening and closing in a couple of seconds. Ran repair of the program, 
> nothing happened.
> I cannot see error messages and don't know where to look for ones.
> Would appreciate your piece of advice.

Attachments won't make it through to the list, Yossif. But your code is
basically something like this:

"""
import sys

def main():
  # calculate stuff
  print(stuff)

if __name__ == '__main__':
  sys.exit(main())
"""

In that case, the program starts (in a console window), runs, prints the
result, and then closes. You've got a few simple ways of seeing the output:

* Run the program from the command line (start a console window in the
directory where the code is and type "ss7calc.py")


https://docs.python.org/3/faq/windows.html#how-do-i-run-a-python-program-under-windows

* Instead of use sys.exit immediately, add input("Press enter...") to
the end of your code:

  https://docs.python.org/3/library/functions.html?highlight=input#input

eg:

result = main()
input("Press enter...")
sys.exit(result)

* set the PYTHONINSPECT environment variable for your user

  https://docs.python.org/3/using/cmdline.html#envvar-PYTHONINSPECT

* Use a shebang line "#!python -i" (without the quotes) at the top of
your program.

  https://docs.python.org/3/using/windows.html#shebang-lines

These last two options will drop into the Python interpreter after your
code has run.

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


Re: .py file won't open in windows 7

2016-02-04 Thread Tim Golden
On 04/02/2016 13:09, Tim Golden wrote:
> On 04/02/2016 12:52, Yossifoff Yossif wrote:
>> Hallow,
>> I try to open a .py file (attached), but what I get is a windows DOS window 
>> opening and closing in a couple of seconds. Ran repair of the program, 
>> nothing happened.
>> I cannot see error messages and don't know where to look for ones.
>> Would appreciate your piece of advice.
> 
> Attachments won't make it through to the list, Yossif. But your code is
> basically something like this:
> 
> """
> import sys
> 
> def main():
>   # calculate stuff
>   print(stuff)
> 
> if __name__ == '__main__':
>   sys.exit(main())
> """
> 
> In that case, the program starts (in a console window), runs, prints the
> result, and then closes. You've got a few simple ways of seeing the output:


... or run within a development environment. Python itself ships with IDLE:

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

but there are plenty of others:

  https://wiki.python.org/moin/IntegratedDevelopmentEnvironments

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


Re: problem in installing python

2016-02-04 Thread Joel Goldstick
On Thu, Feb 4, 2016 at 7:22 AM, Salony Permanand  wrote:

> hello sir,
> During working on python I need urllib2 for my python version 2.7.11.
> Kindly provide me address from where to download it..
> Thanking you.
>
> Hello Salony,

Since this is a new question, its best to start a new thread with a new
title.  You may also want to drop the 'hello sir' greeting.  Yes, mostly
males here, but some very active women also contribute here.  A simple
hello will suffice

As to urllib2, it is included in python so do this in your program:

import urllib2

You may find that the third party library 'requests' is easier to use


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


eval( 'import math' )

2016-02-04 Thread 阎兆珣
   Excuse me for the same problem in Python 3.4.2-32bit

   I just discovered that  function does not necessarily take the
   string input and transfer it to a command to execute.

   So is there a problem with my assumption?

   Thanks

   Option Product Manager

   Gelin Dahua Futures Co.Ltd

    T: +86 10 56711783
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: eval( 'import math' )

2016-02-04 Thread Lutz Horn
Hi,

>I just discovered that  function does not necessarily take the
>string input and transfer it to a command to execute.

Can you please show us the code you try to execute and tells what result you 
expect?

Lutz

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


Re: eval( 'import math' )

2016-02-04 Thread Ian Kelly
On Thu, Feb 4, 2016 at 6:33 AM, 阎兆珣  wrote:
>Excuse me for the same problem in Python 3.4.2-32bit
>
>I just discovered that  function does not necessarily take the
>string input and transfer it to a command to execute.
>
>So is there a problem with my assumption?

eval evaluates an expression, not a statement. For that, you would use exec.

If you're just trying to import though, then you don't need it at all.
Use the importlib.import_module function instead to import a module
determined at runtime. This is more secure than eval or exec, which
can cause any arbitrary Python code to be executed.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: eval( 'import math' )

2016-02-04 Thread Peter Otten
阎兆珣 wrote:

>Excuse me for the same problem in Python 3.4.2-32bit
> 
>I just discovered that  function does not necessarily take the
>string input and transfer it to a command to execute.
> 
>So is there a problem with my assumption?

Python discriminates between statements and expressions. The eval function 
will only accept an expression. OK:

>>> eval("1 + 1")
2
>>> eval("print(42)") # Python 3 only; in Python 2 print is a statement
42
>>> x = y = 1
>>> eval("x > y")
False

Not acceptable:

>>> eval("1+1; 2+2")
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 1
1+1; 2+2
   ^
SyntaxError: invalid syntax

>>> eval("import os")
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 1
import os
 ^
SyntaxError: invalid syntax

>>> eval("if x > y: print(42)")
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 1
if x > y: print(42)
 ^
SyntaxError: invalid syntax

To import a module dynamically either switch to exec()

>>> exec("import os")
>>> os


or use the import_module() function:

>>> import importlib
>>> eval("importlib.import_module('os')")


Of course you can use that function directly

>>> importlib.import_module("os")


and that's what you should do if your goal is to import a module rather than 
to run arbitrary Python code.

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


Re: Tkinter problem: TclError> couldn't connect to display ":0

2016-02-04 Thread gemjack . pb
On Sunday, 29 December 2013 20:20:00 UTC, Michael Matveev  wrote:
> Hi,
> I use live Debian on VM and trying to compile this code.
> 
> 
> import Tkinter
>  
> root = Tkinter.Tk()
>  
> root.title("Fenster 1")
> root.geometry("100x100")
>  
> root.mainloop()
> 
> 
> The shell gives out that kind of message:
> 
> File "test.py", line 5, in 
> root = Tkinter.Tk()
> File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1712, in __init__
> self.tk = _tkinter.create(screenName, baseName, className, interactive, 
> wantobjects, useTk, sync, use)
> _tkinter.TclError: couldn't connect to display ":0"
> 
> 
> 
> thanks for helping out.
> 
> greets.
> Mike

This fixed my problem with thkinter.   sudo cp ~/.Xauthority ~root/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Multiprocess videoplayer

2016-02-04 Thread Ian Kelly
On Thu, Feb 4, 2016 at 2:45 AM,   wrote:
> I have coded a program with python and vlc that plays some videos, but 
> whenever I try to play 3 videos at once, Windows closes the program, I'm 
> guessing that the reason is that one process can't play 3 videos at once (but 
> I don't really know).

My suspicion would be that some uncaught exception is being raised and
killing the whole process.

Since this is a GUI program, are you running it with python.exe or
pythonw.exe? Are you running it from the command line or launching it
from the Windows GUI? If you're not running it from a command prompt
window, try doing that in order to capture any exception output.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How a module is being marked as imported?

2016-02-04 Thread Jean-Charles Lefebvre
So far, I've been advised to:

1/ Double-check that the GIL was correctly acquired
2/ Ensure there's no 'string' module in my project
3/ Manually pre-import commonly used standard modules at interpreter's 
init-time to avoid race conditions due to the multi-threaded nature of the 
running environment

No problem found for 1/ & 2/ (double-checked). I tried 3/ before posting and 
could not reproduce the problem at all which is probably the patch I will apply 
due to the lack of a better solution. I guess I'll have to dig into 
__import__'s code and related.


On Thursday, February 4, 2016 at 11:20:05 AM UTC+1, Jean-Charles Lefebvre wrote:
> Hi all,
> 
> The short version: How CPython marks a module as being fully imported, if it 
> does, so that the same import statement ran from another C thread at the same 
> time does not collide? Or, reversely, does not think the module is not 
> already fully imported?
> 
> The full version: I'm running CPython 3.5.1, embedded into a C++ application 
> on Windows. The application is heavily multi-threaded so several C threads 
> call some Python code at the same time (different Python modules), sharing 
> interpreter's resources by acquiring/releasing the GIL frequently DURING the 
> calls, at language boundaries.
> 
> Sometimes (but always only once per application instance), a call to 
> os.path.expandvars raises the AttributeError exception with message: module 
> 'string' has no attribute 'ascii_letters'. It is raised by the 
> ntpath.expandvars function (line 372). When I noticed the late import 
> statement of the 'string' module at the line above, I thought that MAYBE, it 
> could be because the interpreter is ran in an heavily multi-threaded 
> environment and that the GIL acquiring/releasing occurred at a bad timing? 
> Making me wonder how the import mechanism interacts with the GIL, if it does?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How a module is being marked as imported?

2016-02-04 Thread Kevin Conway
As an attempt to answer your original question, Python doesn't explicitly
mark a module as done. It does keep imports cached in sys.modules, though.
The behaviour you describe where later imports get the same module object
is driven by that cache.

There are cases, such as cyclical imports, where the object in sys.modules
is empty for a period of time and acts as a placeholder until the code from
that module is loaded. During that time, any usage of the module would
result in a similar failure to what you have described.

Additionally, if you are writing multithreaded code then acquiring the GIL
may not be enough. There is another lock used for imports.

On Thu, Feb 4, 2016, 09:43 Jean-Charles Lefebvre 
wrote:

> So far, I've been advised to:
>
> 1/ Double-check that the GIL was correctly acquired
> 2/ Ensure there's no 'string' module in my project
> 3/ Manually pre-import commonly used standard modules at interpreter's
> init-time to avoid race conditions due to the multi-threaded nature of the
> running environment
>
> No problem found for 1/ & 2/ (double-checked). I tried 3/ before posting
> and could not reproduce the problem at all which is probably the patch I
> will apply due to the lack of a better solution. I guess I'll have to dig
> into __import__'s code and related.
>
>
> On Thursday, February 4, 2016 at 11:20:05 AM UTC+1, Jean-Charles Lefebvre
> wrote:
> > Hi all,
> >
> > The short version: How CPython marks a module as being fully imported,
> if it does, so that the same import statement ran from another C thread at
> the same time does not collide? Or, reversely, does not think the module is
> not already fully imported?
> >
> > The full version: I'm running CPython 3.5.1, embedded into a C++
> application on Windows. The application is heavily multi-threaded so
> several C threads call some Python code at the same time (different Python
> modules), sharing interpreter's resources by acquiring/releasing the GIL
> frequently DURING the calls, at language boundaries.
> >
> > Sometimes (but always only once per application instance), a call to
> os.path.expandvars raises the AttributeError exception with message: module
> 'string' has no attribute 'ascii_letters'. It is raised by the
> ntpath.expandvars function (line 372). When I noticed the late import
> statement of the 'string' module at the line above, I thought that MAYBE,
> it could be because the interpreter is ran in an heavily multi-threaded
> environment and that the GIL acquiring/releasing occurred at a bad timing?
> Making me wonder how the import mechanism interacts with the GIL, if it
> does?
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Efficient Wrappers for Instance Methods

2016-02-04 Thread Sven R. Kunze

On 04.02.2016 00:47, Random832 wrote:

On Wed, Feb 3, 2016, at 16:43, Sven R. Kunze wrote:

Actually a nice idea if there were no overhead of creating methods for
all heap instances separately. I'll keep that in mind. :)

What about changing the class of the object to one which is inherited
from its original class and has the method you want? What about reaching
into the class and changing the method in the first place? Either may
not be appropriate, of course, depending on your use case.


There is no base class.

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


Re: Efficient Wrappers for Instance Methods

2016-02-04 Thread Random832
On Thu, Feb 4, 2016, at 11:18, Sven R. Kunze wrote:
> On 04.02.2016 00:47, Random832 wrote:
> > On Wed, Feb 3, 2016, at 16:43, Sven R. Kunze wrote:
> >> Actually a nice idea if there were no overhead of creating methods for
> >> all heap instances separately. I'll keep that in mind. :)
> > What about changing the class of the object to one which is inherited
> > from its original class and has the method you want? What about reaching
> > into the class and changing the method in the first place? Either may
> > not be appropriate, of course, depending on your use case.
> 
> There is no base class.

I meant something like...

Class C:
replace = heapreplace

Cs = {}

...

if not isinstance(x, C)
T = type(x)
cls = cache.get(T)
if cls is None:
   cls = type('C_'+T.__name__, (C, T), {})
x.__class__ = cls

(Of course, by dynamically reassigning __class__ and using the type
constructor, this checks two of the three "crazy type system voodoo"
boxes. I have no idea if it will work, or if I've made a mistake, or if
you'll be able to understand it in six months.)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reply to whom?

2016-02-04 Thread Joel Goldstick
On Thu, Feb 4, 2016 at 12:26 AM, Ben Finney 
wrote:

> Random832  writes:
>
> > On Wed, Feb 3, 2016, at 16:50, Ben Finney wrote:
> > > (You will also have a “reply to all” command. That's almost never
> > > appropriate in a forum like this.)
> >
> > Why not? People reply all to messages I write all the time, and I find
> > it somewhat useful since it separates replies to things I have said
> > from discussions I'm not part of.
>
> That's nice for you that it coincides with what you find useful. For
> those who don't want messages to the forum duplicated in their inbox,
> the behaviour is obnoxious.
>
> In other words: Using “reply to all” on a forum like this is
> inappropriate because you can't know what every participant wants, so
> your set of recipients should be conservative and err on the side of not
> sending a duplicate message to people who didn't ask for it.
>
> --
>  \“Don't worry about people stealing your ideas. If your ideas |
>   `\ are any good, you'll have to ram them down people's throats.” |
> _o__)—Howard Aiken |
> Ben Finney
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

I use gmail and hit reply all and then (usually, unless i forget) delete
all recipients except the group

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


Re: Efficient Wrappers for Instance Methods

2016-02-04 Thread Sven R. Kunze

On 04.02.2016 19:35, Random832 wrote:

On Thu, Feb 4, 2016, at 11:18, Sven R. Kunze wrote:

On 04.02.2016 00:47, Random832 wrote:

On Wed, Feb 3, 2016, at 16:43, Sven R. Kunze wrote:

Actually a nice idea if there were no overhead of creating methods for
all heap instances separately. I'll keep that in mind. :)

What about changing the class of the object to one which is inherited
from its original class and has the method you want? What about reaching
into the class and changing the method in the first place? Either may
not be appropriate, of course, depending on your use case.

There is no base class.

I meant something like...

Class C:
 replace = heapreplace

Cs = {}

...

if not isinstance(x, C)
 T = type(x)
 cls = cache.get(T)
 if cls is None:
cls = type('C_'+T.__name__, (C, T), {})
 x.__class__ = cls

(Of course, by dynamically reassigning __class__ and using the type
constructor, this checks two of the three "crazy type system voodoo"
boxes. I have no idea if it will work, or if I've made a mistake, or if
you'll be able to understand it in six months.)


I think I agree with you that this might be a maintenance nightmare. ;)

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


_siftup and _siftdown implementation

2016-02-04 Thread srinivas devaki
_siftdown function breaks out of the loop when the current pos has a valid
parent.

but _siftup function is not implemented in that fashion, if a valid subheap
is given to the _siftup, it will bring down the root of sub heap and then
again bring it up to its original place.

I was wondering why it is so, is it just to make the code look simple???

Regards
Srinivas Devaki
Junior (3rd yr) student at Indian School of Mines,(IIT Dhanbad)
Computer Science and Engineering Department
ph: +91 9491 383 249
telegram_id: @eightnoteight
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: problem in installing python

2016-02-04 Thread Chris Angelico
On Thu, Feb 4, 2016 at 11:22 PM, Salony Permanand
 wrote:
> During working on python I need urllib2 for my python version 2.7.11.
> Kindly provide me address from where to download it..
> Thanking you.

It should have come with Python. Try it - you should be able to just
use it as-is.

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


Re: _siftup and _siftdown implementation

2016-02-04 Thread Steven D'Aprano
On Fri, 5 Feb 2016 07:50 am, srinivas devaki wrote:

> _siftdown function breaks out of the loop when the current pos has a valid
> parent.
> 
> but _siftup function is not implemented in that fashion, if a valid
> subheap is given to the _siftup, it will bring down the root of sub heap
> and then again bring it up to its original place.
> 
> I was wondering why it is so, is it just to make the code look simple???

Hi Srinivas,

I'm sure that your question is obvious to you, but it's not obvious to us.
Where are _siftup and _siftdown defined? Are they in your code? Somebody
else's code? A library? Which library? What do they do? Where are they
from?




-- 
Steven

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


Re: _siftup and _siftdown implementation

2016-02-04 Thread Sven R. Kunze

On 05.02.2016 01:12, Steven D'Aprano wrote:

On Fri, 5 Feb 2016 07:50 am, srinivas devaki wrote:


_siftdown function breaks out of the loop when the current pos has a valid
parent.

but _siftup function is not implemented in that fashion, if a valid
subheap is given to the _siftup, it will bring down the root of sub heap
and then again bring it up to its original place.

I was wondering why it is so, is it just to make the code look simple???

Hi Srinivas,

I'm sure that your question is obvious to you, but it's not obvious to us.
Where are _siftup and _siftdown defined? Are they in your code? Somebody
else's code? A library? Which library? What do they do? Where are they
from?



The question originated here: 
https://github.com/srkunze/xheap/pull/1#discussion_r51770210



(btw, Steven, your email client somehow breaks my threading view in 
thunderbird. This reply appeared unconnected to Srinivas' post.)

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


Re: _siftup and _siftdown implementation

2016-02-04 Thread srinivas devaki
On Feb 5, 2016 5:45 AM, "Steven D'Aprano"  wrote:
>
> On Fri, 5 Feb 2016 07:50 am, srinivas devaki wrote:
>
> > _siftdown function breaks out of the loop when the current pos has a
valid
> > parent.
> >
> > but _siftup function is not implemented in that fashion, if a valid
> > subheap is given to the _siftup, it will bring down the root of sub heap
> > and then again bring it up to its original place.

as I come to think of it again, it is not subheap, it actually heap cut at
some level hope you get the idea from the usage of _siftup. so even though
the `pos` children are valid the _siftup brings down the new element (i.e
the element which is at first at `pos`) upto its leaf level and then again
it is brought up by using _siftdown. why do the redundant work when it can
simply breakout?

> >
> > I was wondering why it is so, is it just to make the code look simple???
>
> Hi Srinivas,
>
> I'm sure that your question is obvious to you, but it's not obvious to us.
> Where are _siftup and _siftdown defined? Are they in your code? Somebody
> else's code? A library? Which library? What do they do? Where are they
> from?

_siftup and _siftdown are functions from python standard heapq module.

PS: I do competitive programming, I use these modules every couple of days
when compared to other modules. so didn't give much thought when posting to
the mailing list. sorry for that.

Regards
Srinivas Devaki
Junior (3rd yr) student at Indian School of Mines,(IIT Dhanbad)
Computer Science and Engineering Department
ph: +91 9491 383 249
telegram_id: @eightnoteight
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How this C function was called through ctypes this way?

2016-02-04 Thread jfong
eryk sun at 2016/2/4 UTC+8 7:35:17PM wrote:
> > _mod = ctypes.cdll.LoadLibrary(_path)
> 
> Calling ctypes.CDLL directly is preferable since it allows passing
> parameters such as "mode" and "use_errno".
> 
> IMO, the ctypes.cdll and ctypes.windll loaders should be avoided in
> general, especially on Windows, since their attribute-based access
> (e.g. windll.user32) caches libraries, which in turn cache
> function-pointer attributes. You don't want function pointer instances
> being shared across unrelated packages. They may not use compatible
> prototypes and errcheck functions. Each package, module, or script
> should create private instances of CDLL, PyDLL, and WinDLL for a given
> shared library.

Thank you for your detail and deep explanation.

I suppose the reason there are many cases using LoadLibrary() and 
attribute-based access is because it's the way the ctypes tutorial in Python 
document takes. Although both methods has been mentioned in the ctypes 
reference section, but no pros and cons was explained.

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


metaclass

2016-02-04 Thread ast

Hi

I am looking the relationship between some classes
from the enum module


from enum import EnumMeta, Enum



class Color(Enum):

 pass


type(EnumMeta)



EnumMeta.__bases__

(,)




so EnumMeta is a metaclass, it is an instance of type
and inherit from type too.


type(Enum)



Enum.__bases__

(,)

so Enum is an instance of EnumMeta
and Enum inherit from object


type(Color)



Color.__bases__

(,)

so Color is an instance of EnumMeta and
inherit from Enum

It is not obvious to me that Color is an instance
of EnumMeta. Is it a python rule that if a class C
inherit from a class which is an instance of
a metaclass, then class C is an instance of the
same metaclass too ?

Or was it feasible to guess that ?




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


Re: Finding in which class an object's method comes from

2016-02-04 Thread dieter
"ast"  writes:
> Suppose we have:
>
> ClassC inherit from ClassB
> ClassB inherit from ClassA
> ClassA inherit from object
>
> Let's build an object:
>
> obj = ClassC()
>
> Let's invoke an obj method
>
> obj.funct()
>
> funct is first looked in ClassC, then if not found
> on ClassB, then ClassA then object

In Python 2, I am using the following function to find out such
information.

from inspect import getmro

def definedBy(name, class_):
  '''return *class_* base class defining *name*.

  *class_* may (now) also be an object. In this case, its class is used.
  '''
  if not hasattr(class_, '__bases__'): class_ = class_.__class__
  for cl in getmro(class_):
if hasattr(cl,'__dict__'):
  if cl.__dict__.has_key(name): return cl
elif hasattr(cl, name): return cl
  return None
  
(Unlike other approaches reported in this thread)
it not only works for methods but also for other attributes.

I am using this for (interactive) debugging purposes:
usually, I work with Zope/Plone which is a huge software stack
and their it is handy to be able to quickly find out where something
is defined in the code.

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