Re: What does %%(%s)s mean/expand to in Python? What does rowshtml += (rowhtml % ((fieldname, ) * 3)) expand to? Kindly explain.

2014-10-29 Thread Peter Otten
satishmlm...@gmail.com wrote:


> What does %%(%s)s mean in Python?

According to 

https://docs.python.org/2/library/stdtypes.html#string-formatting

in an expression like

"%%(%s)s" % ("foo",)

'%%' expands to '%' and

'%s' expands to 'foo'

so the whole thing gives

>>> "%%(%s)s" % ("foo",)
'%(foo)s'

To this you can then apply another formatting operation that takes a dict as 
its right operand to look up 'foo':

>>> "%(foo)s" % {"foo": "bar"}
'bar'

What you have with "%%(%s)s" is then a template for a template.

> also
> what does
> rowshtml += (rowhtml % ((fieldname,) * 3)) expand to?

(fieldname,)

is a 1-tuple, so

(fieldname,) *3  gives a 3-tuple (fieldname, fieldname, fieldname):

>>> fieldname = "foo"
>>> (fieldname,) * 3
('foo', 'foo', 'foo')

rowhhtml % (fieldname, fieldname, fieldname)

is again string interpolation. Assuming rowhtml contains

"<%s>%s<%s>" may you get

>>> fieldname = "foo"
>>> rowhtml = "<%s>%s"
>>> rowhtml % ((fieldname,)*3)
'foo'


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


Re: What does %%(%s)s mean/expand to in Python? What does rowshtml += (rowhtml % ((fieldname, ) * 3)) expand to? Kindly explain.

2014-10-29 Thread Christian Gollwitzer

Am 29.10.14 07:15, schrieb satishmlm...@gmail.com:

What does %%(%s)s mean in Python?


Instead of posting all those questions here, you can simply try it in an 
interactive python interpreter:


Apfelkiste:VecTcl chris$ python
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> test='%%(%s)s'
>>> test % 'foo'
'%(foo)s'
>>>


also
what does
rowshtml += (rowhtml % ((fieldname,) * 3)) expand to?


>>> fieldname='foo'
>>> (fieldname,)*3
('foo', 'foo', 'foo')
>>> test='first %s second %s third %s'
>>> test % ((fieldname,)*3)
'first foo second foo third foo'
>>>

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


Re: % symbol in python

2014-10-29 Thread Mark Lawrence

On 29/10/2014 05:48, satishmlm...@gmail.com wrote:

kindly let me know
what does
%%(%s)% mean



What did you not understand from the link I posted ten hours ago?

--
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


Meaning of * in the function arguments list

2014-10-29 Thread ast

Hi

Consider the following to_bytes method from integer class:

int.to_bytes(length, byteorder, *, signed=False)

What doest the '*' in the arguments list means ?
--
https://mail.python.org/mailman/listinfo/python-list


Re: Meaning of * in the function arguments list

2014-10-29 Thread Peter Otten
ast wrote:

> Consider the following to_bytes method from integer class:
> 
> int.to_bytes(length, byteorder, *, signed=False)
> 
> What doest the '*' in the arguments list means ?

A bare * indicates that the arguments that follow it are keyword-only:

>>> def f(a, b=2, *, c=3):
... print("a = {}, b = {}, c = {}".format(a, b, c))
... 
>>> f(10)
a = 10, b = 2, c = 3
>>> f(10, 20)
a = 10, b = 20, c = 3
>>> f(10, 20, 30)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: f() takes from 1 to 2 positional arguments but 3 were given
>>> f(10, 20, c=30)
a = 10, b = 20, c = 30


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


Re: memory, PE files, etc...

2014-10-29 Thread Tim Golden
On 29/10/2014 02:18, Denis McMahon wrote:
> On Mon, 27 Oct 2014 10:16:43 -0700, kiuhnm03 wrote:
> 
>> I'd like to write one or more scripts that analyze processes in memory
>> on Windows 7. I used to do these things in C++ by using native Win32 API
>> calls.
>> How should I proceed in python? Any pointers?
> 
> This seems to be a very common request. Does anyone know why?
> 

I certainly wouldn't have called it common, assuming you're referring to
the specific request of analyzing processes in memory. I admit we do see
on and off the more general request of "How do I do in Python on Windows
this thing I can do in C/C++?".

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


Re: Meaning of * in the function arguments list

2014-10-29 Thread ast


"Peter Otten" <__pete...@web.de> a écrit dans le message de 
news:mailman.15291.1414574006.18130.python-l...@python.org...


A bare * indicates that the arguments that follow it are keyword-only:



ok, thx 


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


Python Style Question

2014-10-29 Thread Anton
Let's say I have an incoming list of values *l*. Every element of *l* can be 
one of the following options:
1) an integer value 
2) a string in form of '', e.g. '7'
3) a string with a json serialization of an integer value, e.g. '"7"'
4) something else that should be ignored

I need to transform this list into another list with values from options 1)-3) 
coerced to int. The code below should do this.


Variant 1
===

values = []
for c in l:
# Case 1) or 2)
try:
c_int = int(c)
except ValueError:
pass
else:
values.add(c_int)
continue

# Case 3)
try:
c_int = int(json.loads(c))
except ValueError:
pass
else:
values.add(c_int)
continue

===

Is this code ugly? 
Does it follow EAFP? 
Am I missing something in language best practice?

Or maybe below is more preferable way with a nested try...except clause?

Variant 2
===
values = []
for c in l:
# Case 1) or 2)
try:
c_int = int(c)
except ValueError:

# Case 3)
try:
c_int = int(json.loads(c))
except ValueError:
pass
else:
values.add(c_int)
continue

else:
values.add(c_int)
continue
===

Thanks,
Anton.


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


Re: %%(%s)s mean in python

2014-10-29 Thread Ned Batchelder

On 10/29/14 2:02 AM, satishmlm...@gmail.com wrote:

def fetchRecord(db, form):
  try:


... 34 lines deleted ...


db.close()
print(replyhtml % htmlize(fields))


Why did you paste all this code, it doesn't have the thing you are 
asking about.




What does %%(%s)s mean in Python?



It depends entirely on context. You'll need to find a *small* example of 
what you are asking about so we can help.


--
Ned Batchelder, http://nedbatchelder.com

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


Re: Python Style Question

2014-10-29 Thread Martin Kemp
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 29/10/2014 10:45, Anton wrote:
> Let's say I have an incoming list of values *l*. Every element of
> *l* can be one of the following options: 1) an integer value 2) a
> string in form of '', e.g. '7' 3) a string with a json
> serialization of an integer value, e.g. '"7"' 4) something else
> that should be ignored
> 
> I need to transform this list into another list with values from
> options 1)-3) coerced to int. The code below should do this.
> 
> 
> Variant 1 ===
> 
> values = [] for c in l: # Case 1) or 2) try: c_int = int(c) except
> ValueError: pass else: values.add(c_int) continue
> 
> # Case 3) try: c_int = int(json.loads(c)) except ValueError: pass 
> else: values.add(c_int) continue
> 
> ===
> 
> Is this code ugly? Does it follow EAFP? Am I missing something in
> language best practice?
> 
> Or maybe below is more preferable way with a nested try...except
> clause?
> 
> Variant 2 === values = [] for c in l: # Case 1) or 2) try: c_int =
> int(c) except ValueError:  # Case 3) try: c_int =
> int(json.loads(c)) except ValueError: pass else: values.add(c_int) 
> continue  else: values.add(c_int) continue ===
> 
> Thanks, Anton.
> 
> 

Your first example is perfectly fine and is EAFP

Personally, I prefer to avoid nesting when it's not necessary.

- -- 
Martin Kemp (martin.k...@ingg.com)
-BEGIN PGP SIGNATURE-
Version: GnuPG v2

iQEcBAEBAgAGBQJUUM7zAAoJEJ0Re0UIDzSucugIALn/zY8RdpP8iaMShHoszzqf
I0zl0mFHyqhNtwgQ0ZF7VGO+H+U0Dk8rhzTYOmEMzPTKNBGwll3fda9mOnrK9Xvp
9gQjII6DyQIWH7Z3dLcLr2e1j8OMNUSL6UmAYs8urNSIKZLowdV3JI4G/bLyW0KS
y5Ko8dI6y5nOJ1P9XCmPTmags43UZfR8DrBUaAbzNcS8FGwmUE2KBkEhLQOvmpJi
jmMc7wMOpq0jL+XbA+7pHUqoVZ7w1tUFjuy9I3h45tgPuTFAFB0gX+FpE+oVgO5o
spQpVaOPEYN9ceLgHdKSxzdVIhOQLE6H/SYNHlsEW/ZNM6aR9n4yipgkOmtJ0+M=
=WzHA
-END PGP SIGNATURE-
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Style Question

2014-10-29 Thread Rafael Romero Carmona
Hi, first in Python 2.7.6 and Python 3.4.0 list haven't got any add
function but they have append.

I think you could do better with something like

==
import json
l = [1, -1, 0, '1', '-1', '0', json.dumps(-1), json.dumps(1),
json.dumps(0), 'x', 'sqjklsqjk__', (1, 2)]

values = []

for c in l:
try:
c_int = int(c)
except ValueError:
pass
except TypeError:
pass
else:
values.append(c_int)
continue
print(values)
==

The code has been tested in Python 2.7.6 and 3.4 and returns [1, -1,
0, 1, -1, 0, -1, 1, 0]

You don't need to do two try because you can process both exceptions
in the same way. You don't really need to do json.loads because if you
have a json string which is an integer, you could do that directly
with int(c) which can take a string and transform in an integer.

With ValueError it captures the exception when it tries to transform
the characters' strings and with TypeError it captures the exception
when it tries to work with the tuples.

Have a good day and hope it works for you!

2014-10-29 11:42 GMT+01:00 Anton :
> Let's say I have an incoming list of values *l*. Every element of *l* can be 
> one of the following options:
> 1) an integer value
> 2) a string in form of '', e.g. '7'
> 3) a string with a json serialization of an integer value, e.g. '"7"'
> 4) something else that should be ignored
>
> I need to transform this list into another list with values from options 
> 1)-3) coerced to int. The code below should do this.
>
>
> Variant 1
> ===
>
> values = []
> for c in l:
> # Case 1) or 2)
> try:
> c_int = int(c)
> except ValueError:
> pass
> else:
> values.add(c_int)
> continue
>
> # Case 3)
> try:
> c_int = int(json.loads(c))
> except ValueError:
> pass
> else:
> values.add(c_int)
> continue
>
> ===
>
> Is this code ugly?
> Does it follow EAFP?
> Am I missing something in language best practice?
>
> Or maybe below is more preferable way with a nested try...except clause?
>
> Variant 2
> ===
> values = []
> for c in l:
> # Case 1) or 2)
> try:
> c_int = int(c)
> except ValueError:
>
> # Case 3)
> try:
> c_int = int(json.loads(c))
> except ValueError:
> pass
> else:
> values.add(c_int)
> continue
>
> else:
> values.add(c_int)
> continue
> ===
>
> Thanks,
> Anton.
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Style Question

2014-10-29 Thread Rafael Romero Carmona
2014-10-29 12:25 GMT+01:00 Martin Kemp :
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> On 29/10/2014 10:45, Anton wrote:
>> Let's say I have an incoming list of values *l*. Every element of
>> *l* can be one of the following options: 1) an integer value 2) a
>> string in form of '', e.g. '7' 3) a string with a json
>> serialization of an integer value, e.g. '"7"' 4) something else
>> that should be ignored
>>
>> I need to transform this list into another list with values from
>> options 1)-3) coerced to int. The code below should do this.
>>
>>
>> Variant 1 ===
>>
>> values = [] for c in l: # Case 1) or 2) try: c_int = int(c) except
>> ValueError: pass else: values.add(c_int) continue
>>
>> # Case 3) try: c_int = int(json.loads(c)) except ValueError: pass
>> else: values.add(c_int) continue
>>
>> ===
>>
>> Is this code ugly? Does it follow EAFP? Am I missing something in
>> language best practice?
>>
>> Or maybe below is more preferable way with a nested try...except
>> clause?
>>
>> Variant 2 === values = [] for c in l: # Case 1) or 2) try: c_int =
>> int(c) except ValueError:  # Case 3) try: c_int =
>> int(json.loads(c)) except ValueError: pass else: values.add(c_int)
>> continue  else: values.add(c_int) continue ===
>>
>> Thanks, Anton.
>>
>>
>
> Your first example is perfectly fine and is EAFP
>

Actually it doesn't work because there is no add function and it
doesn't catch the TypeError function to ignore other exceptions than
ValueError. Doesn't it? I tested in Python 2.7.6 and 3.4.

> Personally, I prefer to avoid nesting when it's not necessary.
>
> - --
> Martin Kemp (martin.k...@ingg.com)
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v2
>
> iQEcBAEBAgAGBQJUUM7zAAoJEJ0Re0UIDzSucugIALn/zY8RdpP8iaMShHoszzqf
> I0zl0mFHyqhNtwgQ0ZF7VGO+H+U0Dk8rhzTYOmEMzPTKNBGwll3fda9mOnrK9Xvp
> 9gQjII6DyQIWH7Z3dLcLr2e1j8OMNUSL6UmAYs8urNSIKZLowdV3JI4G/bLyW0KS
> y5Ko8dI6y5nOJ1P9XCmPTmags43UZfR8DrBUaAbzNcS8FGwmUE2KBkEhLQOvmpJi
> jmMc7wMOpq0jL+XbA+7pHUqoVZ7w1tUFjuy9I3h45tgPuTFAFB0gX+FpE+oVgO5o
> spQpVaOPEYN9ceLgHdKSxzdVIhOQLE6H/SYNHlsEW/ZNM6aR9n4yipgkOmtJ0+M=
> =WzHA
> -END PGP SIGNATURE-
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


problem with pefile

2014-10-29 Thread gandalf23
Where is DIRECTORY_ENTRY_LOAD_CONFIG?
In the changelog (https://code.google.com/p/pefile/) one can read:

"Version: 1.2.10-60

Besides some small bugfixes in this release I've added functionality to 
parse the LOAD_CONFIG data directory. Now one can access this structure's 
fields like, for instance, pe.DIRECTORY_ENTRY_LOAD_CONFIG.struct.SecurityCookie 
or pe.DIRECTORY_ENTRY_LOAD_CONFIG.struct.SEHandlerTable"

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


Re: Python Style Question

2014-10-29 Thread Martin Kemp
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 29/10/2014 12:01, Rafael Romero Carmona wrote:
> 2014-10-29 12:25 GMT+01:00 Martin Kemp : On
> 29/10/2014 10:45, Anton wrote:
 Let's say I have an incoming list of values *l*. Every
 element of *l* can be one of the following options: 1) an
 integer value 2) a string in form of '', e.g. '7'
 3) a string with a json serialization of an integer value,
 e.g. '"7"' 4) something else that should be ignored
 
 I need to transform this list into another list with values
 from options 1)-3) coerced to int. The code below should do
 this.
 
 
 Variant 1 ===
 
 values = [] for c in l: # Case 1) or 2) try: c_int = int(c)
 except ValueError: pass else: values.add(c_int) continue
 
 # Case 3) try: c_int = int(json.loads(c)) except ValueError:
 pass else: values.add(c_int) continue
 
 ===
 
 Is this code ugly? Does it follow EAFP? Am I missing
 something in language best practice?
 
 Or maybe below is more preferable way with a nested
 try...except clause?
 
 Variant 2 === values = [] for c in l: # Case 1) or 2) try:
 c_int = int(c) except ValueError:  # Case 3) try: c_int = 
 int(json.loads(c)) except ValueError: pass else:
 values.add(c_int) continue  else: values.add(c_int) continue
 ===
 
 Thanks, Anton.
 
 
> 
> Your first example is perfectly fine and is EAFP
> 
> 
>> Actually it doesn't work because there is no add function and it 
>> doesn't catch the TypeError function to ignore other exceptions
>> than ValueError. Doesn't it? I tested in Python 2.7.6 and 3.4.
> 
> Personally, I prefer to avoid nesting when it's not necessary.
> 
>> -- https://mail.python.org/mailman/listinfo/python-list

Ah ok, style-wise it was fine.

- -- 
Martin Kemp (martin.k...@ingg.com)

-BEGIN PGP SIGNATURE-
Version: GnuPG v2

iQEcBAEBAgAGBQJUUOD+AAoJEJ0Re0UIDzSu1KQIAK6aCMOv4VqOjmm/zoQrmzLf
UGBCLwtHrnDkbXFAIweTSFiM1uf9TDaRpJqY1IrPbJHI4/EAP0Hu07nyx3V6HgzM
/+Wb3DkpjW+JQoVqDSGzE/dTPJcU3/b1/EWWpbu72JHplqz9laEAFt9muWyDPs9u
kDgM06mDd50lsi83W3i0H1iGL6YbLtsik+/x4G4mMjdq1o9BvRpUjkIiOx7yJ/BR
OYzdudltXGqlXcToufHTU2lUv2C0RoHHNO4kytiLoUekCBdGE+Jy/6gQq/AKQu4G
0RYjCOnKNgugfdmDuHi0julPtTEzc+MdY/CcPob4cyy8RDzfQGklGKHP7f9+SJs=
=hjWU
-END PGP SIGNATURE-
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: problem with pefile

2014-10-29 Thread Tim Golden
On 29/10/2014 13:15, gandal...@mail.com wrote:
> Where is DIRECTORY_ENTRY_LOAD_CONFIG? In the changelog
> (https://code.google.com/p/pefile/) one can read:
> 
> "Version: 1.2.10-60
> 
> Besides some small bugfixes in this release I've added functionality
> to parse the LOAD_CONFIG data directory. Now one can access this
> structure's fields like, for instance,
> pe.DIRECTORY_ENTRY_LOAD_CONFIG.struct.SecurityCookie or
> pe.DIRECTORY_ENTRY_LOAD_CONFIG.struct.SEHandlerTable"
> 

I suggest you engage with the maintainers of that project. It appears to
have an issue tracker:

https://code.google.com/p/pefile/issues/list

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


Re: Build Question: How to Add -Wl, --option Before Objects In Setup.py?

2014-10-29 Thread Cyd Haselton
On Tue, Oct 28, 2014 at 4:01 PM, Ned Deily  wrote:
> In article
> ,
>  Cyd Haselton  wrote:
>
>> On Tue, Oct 28, 2014 at 3:11 AM, Ned Deily  wrote:
>> > In article
>> > ,
>> >  Cyd Haselton  wrote:
>> > [...]
>> >> I'm building python on an Android device in the KBOX
>> >> environment...which simulates a Unix type filesystem.
>> >> Python isn't installed; I'm building from sources (2.7.8) with GCC
>> >> 4.8.0 and make.
>> >>
>> >> The problem with the LDFLAGS approach is that some of the libraries
>> >> that must be linked (-lc -ldl) do not need the --allow-shlib-undefined
>> >> option...it's only the lpython2.7 that does.  Any way to do this?
>> >
>> > Sorry, I have no experience with that environment nor an understanding
>> > of why you need to specify --allow-shlib-undefined (it seems to be the
>> > default in some versions of ld).  You could look at and, if necessary,
>> > modify Lib/distutils, the part of the Python standard library that
>> > builds extension modules from setup.py.
>
>> No need to apologize.  Also no need to have an understanding of the
>> environment; with a few rare exceptions it behaves just like a
>> Unix/Linux one.
>>
>> The reason why I need to specify --allow-shlib-undefined is for the
>> python library; it's throwing undefined references to sincos even
>> though the symbol is there. Specifying that option is the only fix
>> I've found.
>>
>> As mentioned earlier, i'm not familiar with python or its build
>> system; which file in the distutils dir do I need to modify?
>
> Perhaps I should apologize for not asking earlier what you are really
> trying to do before suggesting heading down the path of modifying
> Distutils :)  So the issue is with an undefined reference to sincos?  It
> appears that that routine is often supplied in libm.  Is that the case
> on your platform?

Yes it is.

> And, if so, the right fix might be to supply it
> manually or, better, ensure that Python supplies it as a result of
> running ./configure.

If the Makefile generated is a result of running ./configure, then
Python is indeed finding the library...what it is doing with it after
finding it may be something else entirely.  I've tried everything from
adding the -Wl,--no-allow-shlib-undefined option to adding #include
 to the complexobject.c code...I still get an undefined
reference to sincos.  Running
grep "sincos" libpython2.7.* turns up the offending symbol (function?
declaration?) but re-running "make" after that still throws the same
error.

The only fix I've found is adding the -Wl,--allow-shlib-undefined
before the python library...which I do by hacking the Makefile.  That
allows the build to continue, which it does until it hits the part
where setup.py is run.

> Also, what version of Python are you building?

2.7.8.  I thought that it would be easier to build it on Android

>
> --
>  Ned Deily,
>  n...@acm.org
>
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: hotel management system

2014-10-29 Thread Florian Schweikert
On 28/10/14 07:42, ngangsia akumbo wrote:
> Please can someone look at my code and may be advice and may be help me with 
> some correction. I have been learning python for some time now. This is my 
> first project i wish to write. A hotel management system.
> 
> 
> http://pastebin.com/LMHmuTiC

Beside posting the code inline, it would be easier if you had split the
"employee" part and the part with the classes.

I'm not sure what you want to accomplish with this code, but I picked a
few parts:

> if age >= 18:
> pass
> 
> else:
> return age_lim()

using a function just to print a single line is quite overcomplicated.
return the result and handle it on the caller side.
why do you use if/else and just pass first path?

if age<18:
do_something

do the same thing.

I have to guess what the class part should do.

> class Bar:

why calling a class Bar if you use it like some drink counter?

> total_cost = 0
> count = 0

not sure you want to use class variables here, do you want to count
amount of a single type of beer? or everything

> def set_name(self, name):
> self.name = name
> return name

don't use setter if there is 0 logic in the function
also it would be better to set this things in the constructor otherwise
and a setter should not return the name just set

> def set_count(self):
> counts = Bar.count =+ 1

not really readable code style, counts variable is unneccessary here

> # still have to adjust this section
> 
> def set_total_cost(self):  #I am having some errors 
> #calling this functions
> total = set_price() * set_count()
> print "Total cost of drinks: ", total
> pass

well, it's quite obvious this function crashes, you try to use not
defined functions. you have to use self.function_name to access the methods.
But worse than this you want to use (useless) setter to get values and
print them inside the method instead of returning the value and handle
it outside.
Also this is not even a setter, it does not set anything beside a local
variable.

Maybe it would be best you start over again and make one step after
another. Build one part of code and ensure it works before starting with
more code. And ask specific questions if you stuck somewhere.


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


Emulating py2exe for python version 3 and above

2014-10-29 Thread Ian Dickinson
Can i emulate py2exe for python version 3 and above i also use pygame any
suggestions for a basic staring script would be greatly appreciated


Thanks

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


Re: %%(%s)s mean in python

2014-10-29 Thread Thomas Rachel

Am 29.10.2014 07:02 schrieb satishmlm...@gmail.com:


What does %%(%s)s mean in Python?


Weird question, as this has nothing to do with the code you just posted.

In general, what comes up to my mind, is that it is a format string to 
build another format string.


Example:

metafmt = '%%(%s)s'
fieldname = 'myfield'
fmt = metafmt % fieldname
# Now we have a fmt as if it was assigned with '%(myfield)s':
# %% -> %, %s -> myfield.

d = {fieldname: 'my content'}

print fmt % d
# this now prints the given field - which is noted in fieldname -
# from the given dict d.
--
https://mail.python.org/mailman/listinfo/python-list


Send UDP packet to link-local IPv6 address?

2014-10-29 Thread Grant Edwards
How do you send a UDP frame to an IPv6 link-local address?

Initially, I'm most concerned with Linux.

I'm using CPython 2.7.7, but so far all behavior seems to be identical
under 3.3.5, and I need to keep my code compatible with both 2.7 and
3.3/3.4.

I'm particularly interested in sending to the all-nodes multicast
address (ff02::1), but all the experimenting I've done seems to show
that multicast and unicast behave the same.

With link-local addresses you also need to specify which interface to
use. The normal way of doing this on Linux with command-line utilities
is append % to the address/hostname (e.g. ping6 ff02::1%net1).

That doesn't work:

s.sendto(data, ("ff02::1%net1",port))
s.sendto(data, ("fe80::2c0:4eff:fe40:5f%net1",port))

The "%net1" appears to be ignored, and the packet will go out _some_
interface, but I can't figure out how it decides which one (it's not
always the same one).

The only way I've found to send to link-local IPv6 addresses is to use
the extended length destination address tuple of (address, port,
flow_info, scope_id) like so:

s.sendto(data, ("ff02::1",port,0,scope_id))
s.sendto(data, ("fe80::2c0:4eff:fe40:5f",port,0,scope_id))

Through trial and error, I've determined that the valid scope_id
values for my system are 0,2,3,4, and I've found that 4 corresponds to
interface "net1".

After re-reading the Python 2.7 socket module documentation, I can't
find any way to map an interface name to a scope id.  So, after
browsing around /proc, I found the file /proc/net/if_inet6 which
contains:

$ cat if_inet6 
fe80922b34fffe5e7edc 03 40 20 80 net0
0001 01 80 10 80   lo
fdfedcba98760011 04 40 00 80 net1
fe80021b21fffeb1d1e9 04 40 20 80 net1
fdfedcba987600080004 03 40 00 80 net0
fe80922b34fffe5e7ede 02 40 20 80 net2

The first column is obviously the IPv6 address and the last column
the interface name.

It appears that second column is the scope id, and some further
reading has lead me to believe that the fourth column is the scope
(global vs. link-local vs. internal). So I've done the following:

ip6scopeid = {}
for line in open("/proc/net/if_inet6"):
addr, id, _, scope, _, ifacename = line.split()
ip6scopeid[ifacename] = int(id)

This is highly non-portable, but now I can at least send to link-local
addresses like this:

s.sendto(data, ("ff02::1",port,0,ip6scopeid["net1"]))
s.sendto(data, ("fe80::2c0:4eff:fe40:5f",port,0,ip6scopeid["net1"]))

So, my program works (but only on Linux).


What's the pythonic, portable way to do this?


The only other thing I can think of is to make the user specify the
IPv6 address of the interface they want to send from, bind a socket to
that address, then ask for that socket's address:

 s.bind(("fdfe:dcba:9876:10::1",65432))
 print s.getsockname()

The above prints this:

 ('fdfe:dcba:9876:10::1', 5678, 0, 0)
 
so, it unfortunately appears that getsockname() doesn't return the
scope id if you bind to the global address assigned to an interface.  

Trying to bind to the link-local address fails unless you already know
the scope id and pass it to bind:

This fails:  s.bind(("fe80::21b:21ff:feb1:d1e9",5678))
This works:  s.bind(("fe80::21b:21ff:feb1:d1e9",5678,0,4))

But I'm trying to _find_ the scope id, so that isn't helpful.

Any suggestions?

Ideally, I'd like a solution that works on Windows and BSD as well...

-- 
Grant Edwards   grant.b.edwardsYow! Am I SHOPLIFTING?
  at   
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: problem with pefile

2014-10-29 Thread gandalf23
On Wednesday, October 29, 2014 2:39:30 PM UTC+1, Tim Golden wrote:
> On 29/10/2014 13:15, gandalf23 wrote:
> > Where is DIRECTORY_ENTRY_LOAD_CONFIG? In the changelog
> > (https://code.google.com/p/pefile/) one can read:
> > 
> > "Version: 1.2.10-60
> > 
> > Besides some small bugfixes in this release I've added functionality
> > to parse the LOAD_CONFIG data directory. Now one can access this
> > structure's fields like, for instance,
> > pe.DIRECTORY_ENTRY_LOAD_CONFIG.struct.SecurityCookie or
> > pe.DIRECTORY_ENTRY_LOAD_CONFIG.struct.SEHandlerTable"
> > 
> 
> I suggest you engage with the maintainers of that project. It appears to
> have an issue tracker:
> 
> https://code.google.com/p/pefile/issues/list
> 
> TJG

I found out what's the problem by reading the source code.
The attributes DIRECTORY_ENTRY_* are added dynamically to an instance of the 
class PE when/if the corresponding directories are found in the PE file.

OT: how can I hide my email in these posts?
Every time I try to send a post, google warns me that my email is visible and 
so I edit it out.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: problem with pefile

2014-10-29 Thread Kiuhnm
Little test...sorry.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: problem with pefile

2014-10-29 Thread Kiuhnm
On Wednesday, October 29, 2014 4:34:42 PM UTC+1, Kiuhnm wrote:
> OT: how can I hide my email in these posts?
> Every time I try to send a post, google warns me that my email is visible and 
> so I edit it out.

Problem solved :)
-- 
https://mail.python.org/mailman/listinfo/python-list


optional types

2014-10-29 Thread Kiuhnm
I must say that the lack of static types in Python is a pain in the neck 
especially when I'm exploring new libraries.
Recently, I learned a new language called Dart which have optional typing and I 
had a lot of fun with it. Basically, you use type annotations as documentation 
and to give useful information to the IDE or editor. That makes the IDE look 
*very* smart!
I'm using PyCharm and more often than not I want to see the list of methods and 
attributes of an object, but the editor won't show them to me because it 
doesn't know the dynamic type of the variable whose value was just returned by 
a function.
That's irritating!
Am I the only one who'd like to see optional types introduced in Python?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Send UDP packet to link-local IPv6 address?

2014-10-29 Thread Alain Ketterlin
Grant Edwards  writes:

[...]
> With link-local addresses you also need to specify which interface to
> use. The normal way of doing this on Linux with command-line utilities
> is append % to the address/hostname (e.g. ping6 ff02::1%net1).
>
> That doesn't work:
>
> s.sendto(data, ("ff02::1%net1",port))
> s.sendto(data, ("fe80::2c0:4eff:fe40:5f%net1",port))
>
> The "%net1" appears to be ignored, and the packet will go out _some_
> interface, but I can't figure out how it decides which one (it's not
> always the same one).

The only way I've found is to use socket.getaddrinfo(), which does
accept "%net1" after the IPv6 address, and returns scope_id (actually a
complete sockaddr). I can't access my files now, by I think

socket.getaddrinfo("fe80::2c0:4eff:fe40:5f%net1",port,...)

should work for you (family, socktype etc should be passed also to avoid
searching the results of getaddrinfo()).

Hope this helps,

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


Re: optional types

2014-10-29 Thread Peter Otten
Kiuhnm wrote:

> I must say that the lack of static types in Python is a pain in the neck
> especially when I'm exploring new libraries. Recently, I learned a new
> language called Dart which have optional typing and I had a lot of fun
> with it. Basically, you use type annotations as documentation and to give
> useful information to the IDE or editor. That makes the IDE look *very*
> smart! I'm using PyCharm and more often than not I want to see the list of
> methods and attributes of an object, but the editor won't show them to me
> because it doesn't know the dynamic type of the variable whose value was
> just returned by a function. That's irritating! Am I the only one who'd
> like to see optional types introduced in Python?

Personally I am skeptical, but there is an effort underway:

http://www.mypy-lang.org/
https://mail.python.org/pipermail/python-ideas/2014-August/028742.html

Nothing that your search engine of choice could not have found you...

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


Re: optional types

2014-10-29 Thread Kiuhnm
On Wednesday, October 29, 2014 5:57:13 PM UTC+1, Peter Otten wrote:
> Kiuhnm wrote:
> 
> > I must say that the lack of static types in Python is a pain in the neck
> > especially when I'm exploring new libraries. Recently, I learned a new
> > language called Dart which have optional typing and I had a lot of fun
> > with it. Basically, you use type annotations as documentation and to give
> > useful information to the IDE or editor. That makes the IDE look *very*
> > smart! I'm using PyCharm and more often than not I want to see the list of
> > methods and attributes of an object, but the editor won't show them to me
> > because it doesn't know the dynamic type of the variable whose value was
> > just returned by a function. That's irritating! Am I the only one who'd
> > like to see optional types introduced in Python?
> 
> Personally I am skeptical, but there is an effort underway:
> 
> http://www.mypy-lang.org/
> https://mail.python.org/pipermail/python-ideas/2014-August/028742.html
> 
> Nothing that your search engine of choice could not have found you...

In fact, I did find it, but that didn't stop me from asking :)

You can find something similar for almost any dynamic language out there.
If it isn't an official feature of the language, it's useless, IMHO.

It seems that PyCharm supports some kind of type annotations:
http://www.jetbrains.com/pycharm/webhelp/using-docstrings-to-specify-types.html
Unfortunately, again, if almost no one uses them, they're not very useful.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: optional types

2014-10-29 Thread Chris Angelico
On Thu, Oct 30, 2014 at 4:18 AM, Kiuhnm  wrote:
>> Personally I am skeptical, but there is an effort underway:
>>
>> http://www.mypy-lang.org/
>> https://mail.python.org/pipermail/python-ideas/2014-August/028742.html
>>
>> Nothing that your search engine of choice could not have found you...
>
> In fact, I did find it, but that didn't stop me from asking :)
>
> You can find something similar for almost any dynamic language out there.
> If it isn't an official feature of the language, it's useless, IMHO.

As you'll see from the python-ideas thread, there's a proposal
under-way to *make* this an official feature. However, it's massively
open to bikeshedding :) If you feel strongly about this, come join us
on python-ideas and weigh in; all input will be warmly received, and
that doesn't mean we respond with flames... not usually, anyway!

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


Re: Send UDP packet to link-local IPv6 address?

2014-10-29 Thread Grant Edwards
On 2014-10-29, Alain Ketterlin  wrote:
> Grant Edwards  writes:
>
> [...]
>> With link-local addresses you also need to specify which interface to
>> use. The normal way of doing this on Linux with command-line utilities
>> is append % to the address/hostname (e.g. ping6 ff02::1%net1).
>>
>> That doesn't work:
>>
>> s.sendto(data, ("ff02::1%net1",port))
>> s.sendto(data, ("fe80::2c0:4eff:fe40:5f%net1",port))
>>
>> The "%net1" appears to be ignored, and the packet will go out _some_
>> interface, but I can't figure out how it decides which one (it's not
>> always the same one).
>
> The only way I've found is to use socket.getaddrinfo(), which does
> accept "%net1" after the IPv6 address, and returns scope_id (actually a
> complete sockaddr). I can't access my files now, by I think
>
> socket.getaddrinfo("fe80::2c0:4eff:fe40:5f%net1",port,...)
>
> should work for you (family, socktype etc should be passed also to avoid
> searching the results of getaddrinfo()).

Doh!, of course that works.  Using getaddrinfo() is how you're always
supposed to do things these days.  Creating an address tuple by hand
is a bad habit left over from too many years spent doing network stuff
in the old days before getaddrinfo et al.  I looked at the
documentation for getaddrinfo(), and I would have sworn I had tried it
and couldn't get it to work.  But it does.

> Hope this helps,

Definitely!

Thanks!

-- 
Grant Edwards   grant.b.edwardsYow! FOOLED you!  Absorb
  at   EGO SHATTERING impulse
  gmail.comrays, polyester poltroon!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: optional types

2014-10-29 Thread Ethan Furman

On 10/29/2014 10:18 AM, Kiuhnm wrote:

On Wednesday, October 29, 2014 5:57:13 PM UTC+1, Peter Otten wrote:

Kiuhnm wrote:


I must say that the lack of static types in Python is a pain in the neck
especially when I'm exploring new libraries. Recently, I learned a new
language called Dart which have optional typing and I had a lot of fun
with it. Basically, you use type annotations as documentation and to give
useful information to the IDE or editor. That makes the IDE look *very*
smart! I'm using PyCharm and more often than not I want to see the list of
methods and attributes of an object, but the editor won't show them to me
because it doesn't know the dynamic type of the variable whose value was
just returned by a function. That's irritating! Am I the only one who'd
like to see optional types introduced in Python?


Personally I am skeptical, but there is an effort underway:

http://www.mypy-lang.org/
https://mail.python.org/pipermail/python-ideas/2014-August/028742.html

Nothing that your search engine of choice could not have found you...


In fact, I did find it, but that didn't stop me from asking :)

You can find something similar for almost any dynamic language out there.
If it isn't an official feature of the language, it's useless, IMHO.

It seems that PyCharm supports some kind of type annotations:
http://www.jetbrains.com/pycharm/webhelp/using-docstrings-to-specify-types.html
Unfortunately, again, if almost no one uses them, they're not very useful.


Even if it becomes official, which seems likely, it will still be optional -- hence, only useful if folks actually use 
it.  ;)


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


Re: optional types

2014-10-29 Thread Chris Angelico
On Thu, Oct 30, 2014 at 4:46 AM, Ethan Furman  wrote:
> Even if it becomes official, which seems likely, it will still be optional
> -- hence, only useful if folks actually use it.  ;)

Yes, but if it's official, the standard library (large parts of it, at
least) will use it, which will make it a lot more useful than it
currently is.

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


Re: Anyone know the solution

2014-10-29 Thread Denis McMahon
On Mon, 27 Oct 2014 08:10:04 -0700, emmanueloje wrote:

> Write a program ...

Hey dudester

I coded a solution for you, you can get it here:

http://www.sined.co.uk/tmp/names.py.txt

Make sure you leave all the comments in so your instructor realises how 
much effort you went in to in researching how to code this.

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


Re: optional types

2014-10-29 Thread Marko Rauhamaa
Chris Angelico :

> Yes, but if it's official, the standard library (large parts of it, at
> least) will use it, which will make it a lot more useful than it
> currently is.

I doubt it. Python should decide if it wants to stay Python or become
another Java. I don't really believe in this "be everything for
everybody" thing. You'll only become nothing for anybody.


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


Re: optional types

2014-10-29 Thread Chris Angelico
On Thu, Oct 30, 2014 at 5:18 AM, Marko Rauhamaa  wrote:
> Chris Angelico :
>
>> Yes, but if it's official, the standard library (large parts of it, at
>> least) will use it, which will make it a lot more useful than it
>> currently is.
>
> I doubt it. Python should decide if it wants to stay Python or become
> another Java. I don't really believe in this "be everything for
> everybody" thing. You'll only become nothing for anybody.

Mebbe. More likely, Python wants to lift ideas from anyone and
everyone. List comprehensions came from the functional world, flexible
string representation came from Pike or bash (or was independently
invented), etc, etc.

Python won't turn into Java. The biggest philosophical difference
between the languages, as I see it, is Java's rigidity of boundaries
versus Python's consenting-adults policy. In Java, you write getters
and setters for everything, you lock your class up and make sure
people use it ONLY in the ways you've specified, you declare
parameters/return values/exceptions so people know exactly what to
expect, etc. Python gets out of your way and lets you write a single
application as a concerted whole; if you want to "reach in" and fiddle
with another class's members, go for it. I'm not saying that either
philosophy is *wrong*, of course, but just adding type hints to Python
isn't going to change the underlying philosophical model.

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


Re: optional types

2014-10-29 Thread Nick Cash
> Am I the only one who'd like to see optional types introduced in Python?

Nope! Some dude named "Guido" would like to see them as well:
https://mail.python.org/pipermail/python-ideas/2014-August/028742.html

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


Re: optional types

2014-10-29 Thread Kiuhnm
On Wednesday, October 29, 2014 7:19:11 PM UTC+1, Marko Rauhamaa wrote:
> Chris Angelico :
> 
> > Yes, but if it's official, the standard library (large parts of it, at
> > least) will use it, which will make it a lot more useful than it
> > currently is.
> 
> I doubt it. Python should decide if it wants to stay Python or become
> another Java. I don't really believe in this "be everything for
> everybody" thing. You'll only become nothing for anybody.
> 
> 
> Marko

1) Java is not optionally typed.
2) Having optional types is not "being everything for everybody", it's just 
being smart.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: optional types

2014-10-29 Thread Marko Rauhamaa
Kiuhnm :

> 2) Having optional types is not "being everything for everybody", it's
> just being smart.

We'll see, we'll see...


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


Re: Python Style Question

2014-10-29 Thread Anton
On Wednesday, October 29, 2014 4:43:33 AM UTC-7, Rafael Romero Carmona wrote:
> Hi, first in Python 2.7.6 and Python 3.4.0 list haven't got any add
> function but they have append.
You are right, in my original code I use set instead of array, so it should be 
either values = set() or values.append() in the original code.
> 
> I think you could do better with something like
> 
> ==
> import json
> l = [1, -1, 0, '1', '-1', '0', json.dumps(-1), json.dumps(1),
> json.dumps(0), 'x', 'sqjklsqjk__', (1, 2)]
It should also work with cases like [1, json.dumps('-1')], which is case 3), 
sorry if it was not clear in the initial post.
> 
> values = []
> 
> for c in l:
> try:
> c_int = int(c)
> except ValueError:
> pass
> except TypeError:
> pass
> else:
> values.append(c_int)
> continue
> print(values)
> ==
> 
> The code has been tested in Python 2.7.6 and 3.4 and returns [1, -1,
> 0, 1, -1, 0, -1, 1, 0]
> 
> You don't need to do two try because you can process both exceptions
> in the same way. You don't really need to do json.loads because if you
> have a json string which is an integer, you could do that directly
> with int(c) which can take a string and transform in an integer.
In case of 3) an element can be a string like '"1"', which will fail int(...), 
in this case it tries to parse it with json.


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


Re: optional types

2014-10-29 Thread Kiuhnm
On Wednesday, October 29, 2014 8:03:16 PM UTC+1, Kiuhnm wrote:
> On Wednesday, October 29, 2014 7:19:11 PM UTC+1, Marko Rauhamaa wrote:
> > Chris Angelico :
> > 
> > > Yes, but if it's official, the standard library (large parts of it, at
> > > least) will use it, which will make it a lot more useful than it
> > > currently is.
> > 
> > I doubt it. Python should decide if it wants to stay Python or become
> > another Java. I don't really believe in this "be everything for
> > everybody" thing. You'll only become nothing for anybody.
> > 
> > 
> > Marko
> 
> 1) Java is not optionally typed.
> 2) Having optional types is not "being everything for everybody", it's just 
> being smart.

...where "smart" is referred to IDEs, etc...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: optional types

2014-10-29 Thread Mark Lawrence

On 29/10/2014 19:03, Kiuhnm wrote:

On Wednesday, October 29, 2014 7:19:11 PM UTC+1, Marko Rauhamaa wrote:

Chris Angelico :


Yes, but if it's official, the standard library (large parts of it, at
least) will use it, which will make it a lot more useful than it
currently is.


I doubt it. Python should decide if it wants to stay Python or become
another Java. I don't really believe in this "be everything for
everybody" thing. You'll only become nothing for anybody.


Marko


1) Java is not optionally typed.
2) Having optional types is not "being everything for everybody", it's just 
being smart.



Regarding 2) Python has somehow managed without optional types for over 
20 years so it's my belief that they're not the panacea that so many 
people think they are.  Sure if they get implemented and if they improve 
Python then I'm all for them, but I'm not holding my breath.


--
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 Style Question

2014-10-29 Thread Anton
On Wednesday, October 29, 2014 4:59:25 AM UTC-7, Rafael Romero Carmona wrote:
> 2014-10-29 12:25 GMT+01:00 Martin Kemp :
> Actually it doesn't work because there is no add function and it
> doesn't catch the TypeError function to ignore other exceptions than
> ValueError. Doesn't it? I tested in Python 2.7.6 and 3.4.
Originally I was using set instead of list. So it should have been either 
values = set() or values.append(), but it is not relevant to the question.
Regarding TypeError, I don't catch it on purpose, because I want this type of 
Exception to bubble up and surface as an error and be logged, because this 
should never be the case. I expect an element to be either something coercible 
to int or a string. If for some reason it is an object, then there is something 
wrong one layer up, so I want it to fail explicitly. 


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


Re: (-1)**1000

2014-10-29 Thread Stefan Behnel
Ned Batchelder schrieb am 26.10.2014 um 21:45:
> On 10/26/14 4:07 PM, Tony the Tiger wrote:
>> On Wed, 22 Oct 2014 10:27:34 +0200, ast wrote:
>>
>>> If i am writing (-1)**1000 on a python program, will the interpreter do
>>> (-1)*(-1)*...*(-1) or something clever ?
>>
>> Even vs. odd. It ought to know. I would assume from a set of defined
>> rules how math works.
> 
> There is such a thing as an optimization that isn't worthwhile to perform,
> simply because it's expected to provide so little benefit.  The language
> implementors have to trade off the cost of adding the optimization to the
> implementation, against the possible benefit people would get from it.
> 
> Benefit in this case would have to include a guess as to how often real
> programs would hit the optimization case.

... and also compare it to the number of cases where the optimisation
(which may, for example, need to check for an optimisable value or set of
values) slows down the generic (unoptimised) code path that is actually taken.

Even if the code impact on the implementation is small enough to be
acceptable, an optimisation for unlikely cases may provide a net-loss for
the "normal" code. So there are several reasons why an "obvious"
optimisation may be a bad idea.

Stefan


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


Re: optional types

2014-10-29 Thread Marko Rauhamaa
Mark Lawrence :

> Regarding 2) Python has somehow managed without optional types for
> over 20 years so it's my belief that they're not the panacea that so
> many people think they are. Sure if they get implemented and if they
> improve Python then I'm all for them, but I'm not holding my breath.

I'm afraid of stylistic chaos and optional types turning into de-facto
mandatory types as modules interface each other.


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


Re: optional types

2014-10-29 Thread Kiuhnm
On Wednesday, October 29, 2014 8:45:08 PM UTC+1, Marko Rauhamaa wrote:
> Mark Lawrence :
> 
> > Regarding 2) Python has somehow managed without optional types for
> > over 20 years so it's my belief that they're not the panacea that so
> > many people think they are. Sure if they get implemented and if they
> > improve Python then I'm all for them, but I'm not holding my breath.
> 
> I'm afraid of stylistic chaos and optional types turning into de-facto
> mandatory types as modules interface each other.

The only problem I see is that Python's type system might become too complex 
(Scala anyone???)
If you start adding covariance, contravariance, F-bounded types, etc..., the 
type system becomes more of a hindrance, IMHO.
But if you keep it simple (like Dart) it shouldn't get in your way.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: optional types

2014-10-29 Thread Kiuhnm
On Wednesday, October 29, 2014 8:23:30 PM UTC+1, Mark Lawrence wrote:
> On 29/10/2014 19:03, Kiuhnm wrote:
> > On Wednesday, October 29, 2014 7:19:11 PM UTC+1, Marko Rauhamaa wrote:
> >> Chris Angelico :
> >>
> >>> Yes, but if it's official, the standard library (large parts of it, at
> >>> least) will use it, which will make it a lot more useful than it
> >>> currently is.
> >>
> >> I doubt it. Python should decide if it wants to stay Python or become
> >> another Java. I don't really believe in this "be everything for
> >> everybody" thing. You'll only become nothing for anybody.
> >>
> >>
> >> Marko
> >
> > 1) Java is not optionally typed.
> > 2) Having optional types is not "being everything for everybody", it's just 
> > being smart.
> >
> 
> Regarding 2) Python has somehow managed without optional types for over 
> 20 years so it's my belief that they're not the panacea that so many 
> people think they are.  Sure if they get implemented and if they improve 
> Python then I'm all for them, but I'm not holding my breath.

The only thing I know is that I programmed in ASM and C++ for many years and I 
liked it. Then I moved to C#, Haskell, Scala, and many other languages. Then I 
learned Python and I liked it. Then I tried Dart (with optional static typing) 
and liked it very much. Finally, I've come back to Python and I don't like it 
anymore like I used to. Dart's syntax is not on par with Python's but its type 
system is so lightweight and non intrusive that it's a joy to work with it and 
I miss it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.4.2 + PyQt4 + PyCharm 3.4.1

2014-10-29 Thread Juan Christian
It only occurs whule using PyCharm I tried it via pure terminal and
everything works... =/

On Tue, Oct 28, 2014 at 7:45 PM, Juan Christian 
wrote:

> Python 3.4.2 Windows x64
> PyQt4 4.11.2 Py3.4 Qt4.8.6 (x64)
> PyCharm 3.4.1 Pro Edition
>
>
> So, PyCharm works 100% with everything here but PyQt.
>
> I have this folder structure:
>
> Disk C:
> > PyQt4
> >> Lib/site-packages/PyQt4/(tons of files here)
>
> > Python34 (normal/default installation)
>
> ---
>
> I tried copying the 'PyQt4' folder to my 'Python34/Lib/site-packages'
> folder but when I try to code something Qt related on PyCharm I get this
> issue:
>
> Some skeletons failed to generate: 19 modules failed in 1 interpreter.
> Details...
>
> Failed modules
>
> Python 3.4.2
> PyQt4.QAxContainer
> PyQt4.Qsci
> PyQt4.QtCore
> PyQt4.QtDeclarative
> PyQt4.QtDesigner
> PyQt4.QtGui
> PyQt4.QtHelp
> PyQt4.QtMultimedia
> PyQt4.QtNetwork
> PyQt4.QtOpenGL
> PyQt4.QtScript
> PyQt4.QtScriptTools
> PyQt4.QtSql
> PyQt4.QtSvg
> PyQt4.QtTest
> PyQt4.QtWebKit
> PyQt4.QtXml
> PyQt4.QtXmlPatterns
> PyQt4.phonon
>
> Generation of skeletons for the modules above will be tried again when the
> modules are updated or a new version of generator is available.
>
> And PyCharm tells me that my 'import PyQt4.ANYTHING_HERE import *' has
> 'Unresolved references'.
>
> ---
>
> When I try to install the PyQt4 via the installer, in the default location
> (C:/Python34) I get an even 'worse' error, whenever PyCharm try to update
> the skeletons or something like that (that is, whenever I open a file
> there...), I get tons and tons of the same error, 'Error while accessing
> memory at address ', and 'python.exe' stops working.
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Anyone know the solution

2014-10-29 Thread Anton
On Tuesday, October 28, 2014 10:13:14 PM UTC-7, Gregory Ewing wrote:
> No, that's not the correct answer. Being NP-complete doesn't
> mean something is impossible, or even hard to do. All it
> means is that nobody knows of a cleverer solution than
> just trying all possibilities. That's only a difficulty if
> the problem is large enough; often it won't be.

Why do you need to iterate over all possibilities solving this problem anyway?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What for -- for? (was A bug?)

2014-10-29 Thread Terry Reedy

On 10/29/2014 1:42 AM, Zachary Ware wrote:

to avoid inconvenient line-wrapping (that I can avoid just by
sticking to 80 column lines in the first place:).


Try perhaps 65 for email.

def get_abc_map(cls):
return {n: issubclass(cls, getattr(abc, n))
for n in dir(abc) if n[0].isupper()}

is less than 55 and should not get linewrapped on any sensible sender or 
reader.


--
Terry Jan Reedy

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


Re: Meaning of * in the function arguments list

2014-10-29 Thread Terry Reedy

On 10/29/2014 4:56 AM, ast wrote:


Consider the following to_bytes method from integer class:
int.to_bytes(length, byteorder, *, signed=False)
What doest the '*' in the arguments list means ?


If you go to the online doc index page for Symbols,
https://docs.python.org/3/genindex-Symbols.html
there a 3 entries for the use of * as an operator, in statements (in 
particular, def for functions), and in function calls.


--
Terry Jan Reedy

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


Re: optional types

2014-10-29 Thread Terry Reedy

On 10/29/2014 4:40 PM, Kiuhnm wrote:


The only thing I know is that I programmed in ASM and C++ for many
years and I liked it. Then I moved to C#, Haskell, Scala, and many
other languages. Then I learned Python and I liked it. Then I tried
Dart (with optional static typing) and liked it very much. Finally,
I've come back to Python and I don't like it anymore like I used to.
Dart's syntax is not on par with Python's but its type system is so
lightweight and non intrusive that it's a joy to work with it and I
miss it.


Then propose on python-ideas, probably best after posting more here, 
that Dart be used as a model for Python.  But include a summary or 
example of what it is and why you like it and how you think its system 
might be adapted to Python.  Would it be based on the current 
annotations, for instance?


--
Terry Jan Reedy

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