Serious error in int() function?

2016-04-13 Thread martin . spichty
Hi,

there may be a serious error in python's int() function:

print int(float(2.8/0.1))

yields

27

instead of 28!!

I am using Python Python 2.7.6, GCC 4.8.2 on Linux Ubuntu.

Is that known?
Best,
Martin
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Serious error in int() function?

2016-04-13 Thread Marko Rauhamaa
[email protected]:

> there may be a serious error in python's int() function:
>
> print int(float(2.8/0.1))
>
> yields
>
> 27
>
> instead of 28!!

It is not an error but a normal artifact of decimal-to-binary
conversion.


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


Re: Serious error in int() function?

2016-04-13 Thread Peter Otten
[email protected] wrote:

> Hi,
> 
> there may be a serious error in python's int() function:
> 
> print int(float(2.8/0.1))
> 
> yields
> 
> 27
> 
> instead of 28!!
> 
> I am using Python Python 2.7.6, GCC 4.8.2 on Linux Ubuntu.
> 
> Is that known?

Yes. C has the same error as has every other language that uses the floating 
point numbers supported by your computer's hardware. See

https://docs.python.org/2/tutorial/floatingpoint.html

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


Re: Serious error in int() function?

2016-04-13 Thread Alain Ketterlin
[email protected] writes:

> print int(float(2.8/0.1))
>
> yields
>
> 27
>
> instead of 28!!

That's how floating-point arithmetic works: look at the result of
2.8/0.1 to see why int() is correct.

> Is that known?

Yes, it is known, and correct since you use "float". See
http://floating-point-gui.de/ for a nice explanation. Use decimal
(https://docs.python.org/2/library/decimal.html) if you need exact
representations.

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


Re: Serious error in int() function?

2016-04-13 Thread blindanagram
On 13/04/2016 08:41, [email protected] wrote:
> Hi,
> 
> there may be a serious error in python's int() function:
> 
> print int(float(2.8/0.1))
> 
> yields
> 
> 27
> 
> instead of 28!!
> 
> I am using Python Python 2.7.6, GCC 4.8.2 on Linux Ubuntu.
> 
> Is that known?

This arises because finite floating point arithmetic is not exact so
2.8/0.1 results in 27.996.  And, since the int() function
truncates towards zero, this results in a value of 27.

If you want the nearest integer you should use round(x) rather than int(x).

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


Re: The reason I uninstalled Python 3.5.1 (32-bit) for Windows

2016-04-13 Thread Tim Golden
On 13/04/2016 03:57, Jason Honeycutt wrote:
> Hello,
> 
> I am providing feedback as to why I just uninstalled Python. I could not
> use pip. My command line would not recognize pip.exe as a file, even though
> I could see the file listed when I type "dir" in the Scripts folder.
> 
> I tried to repair Python; however, then the file did not show up at all.
> 
> I'm going to try to download the 64-bit version and see if that helps.

Thanks for taking the trouble to post, Jason. We very much need to get
some better support for the 3.5 install on Windows where many things
have been changed (including the entire installation mechanism) and
which is using the bleeding edge of Visual Studio *and* WiX. However,
until we get around to that...

If you just want to get moving with Python (and you're having problems
with the 3.5 install as you are) just use the 3.4 installer -- unless
you specifically want 3.5 features.

If you definitely want the 3.5 install, and you have no joy with the
python.org installers, you might want to consider the Anaconda installer:

  https://www.continuum.io/downloads

which is built differently and (probably) doesn't have the same

Obviously we need to understand and fix our own installer issues (or at
least to document what problems are) but in the meantime I hope one of
those suggestions is fruitful for you.

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


Re: real time FM synthesizer

2016-04-13 Thread jkn
Hi Irmen

On Wednesday, April 13, 2016 at 12:22:25 AM UTC+1, Irmen de Jong wrote:
> It seems that Python is fast enough [1] to create a real time FM music 
> synthesizer
> (think Yamaha DX-7). I made one that you can see here:
>   https://github.com/irmen/synthesizer
> 
> The synthesizer can create various waveforms (sine, sawtooth, pulse etc.) and 
> lets you
> modify them in various ways. You can apply FM (frequency modulation), PWM 
> (pulse-width
> modulation), volume envelopes, vibrato, and reverb/echo. It is primarily 
> based around
> oscillators that are represented as generator functions in the code.
> A GUI is provided that gives access to most of the features interactively, 
> and lets you
> play a tune with your created FM instrument on a piano keyboard.
> 
> You will need Python 3.x and pyaudio to be able to hear sound, and matplotlib 
> if you
> want to see graphical diagrams of generated waveforms.
> 
> I can't create nice music myself but this was a fun project to build and to 
> learn how FM
> synthesizers work internally :)
> 
> 
> 
> Irmen
> 
> 
> [1]: meaning it can generate and play fairly complex waveforms based on 
> multiple
> oscillators and filters in real time in one 44.1 kHz audio channel. That is 
> on a 3.2 ghz
> machine.  With enough oscillator/filters combined however it starts to 
> stutter and
> cannot do it anymore in real time. However you can still generate those 
> waveforms and
> save them to a .wav on disk to play afterwards.  The code only uses one CPU 
> core though
> so maybe there's room for improvement.

This looks fantastic - I am sure I can have a lot of fun with this. Thanks for 
publicising.

Regards
Jon N
-- 
https://mail.python.org/mailman/listinfo/python-list


Enum questions.

2016-04-13 Thread Antoon Pardon
I have been looking at the enum documentation and it
seems enums are missing two features I rather find
important.

1) Given an Enum value, someway to get the next/previous
   one

2) Given two Enum values, iterate over the values between
   them.

Did I miss those in the documentation or are they really
missing?

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


Re: Enum questions.

2016-04-13 Thread Rustom Mody
On Wednesday, April 13, 2016 at 3:43:41 PM UTC+5:30, Antoon Pardon wrote:
> I have been looking at the enum documentation and it
> seems enums are missing two features I rather find
> important.
> 
> 1) Given an Enum value, someway to get the next/previous
>one
> 
> 2) Given two Enum values, iterate over the values between
>them.
> 
> Did I miss those in the documentation or are they really
> missing?

Given the eg in the docs:
from enum import Enum
class Color(Enum):
red = 1
blue = 2
green = 3

>>> Color(Color.red.value+1)


>>> for i in range(Color.red.value,Color.green.value+1):
...   print (Color(i))
... 
Color.red
Color.blue
Color.green


If you say that is clunky I wont argue :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Enum questions.

2016-04-13 Thread Marko Rauhamaa
Rustom Mody :

> Given the eg in the docs:
> from enum import Enum
> class Color(Enum):
> red = 1
> blue = 2
> green = 3
>
 Color(Color.red.value+1)
> 

But:

   >>> class Color(enum.Enum):
   ...   red = 0xff
   ...   green = 0x00ff00
   ...   blue = 0xff
   ...
   >>> Color(Color.red.value + 1)
   Traceback (most recent call last):
 File "", line 1, in 
 File "/usr/lib64/python3.4/enum.py", line 222, in __call__
   return cls.__new__(cls, value)
 File "/usr/lib64/python3.4/enum.py", line 457, in __new__
   raise ValueError("%r is not a valid %s" % (value, cls.__name__))
   ValueError: 16711681 is not a valid Color

I take it that enums in Python are identifiers only. While you can
iterate over all enums (and the definition order is preserved), it is
simply a way to operate on *all* enums.

So the answer to the OP's question is: that feature is not supported.


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


Re: Serious error in int() function?

2016-04-13 Thread Gregory Ewing

[email protected] wrote:

print int(float(2.8/0.1))

yields

27

instead of 28!!


This is a consequence of the fact that the machine does
floating point arithmetic in binary, not decimal.

0.1 is not exactly representable as a binary floating
point number, and the result of the division comes out
very slightly less that 28:

>>> 2.8/0.1
27.996

This is not unique to Python; you'll get the same
result from anything that uses the machine's native
floating point numbers.

When using floating point, you always need to be
prepared for slight inaccuracies. Usually you don't
notice them, because the results are rounded to some
reasonable number of decimal places before display.
But sometimes they show up, such as when using
int(), which truncates instead of rounding.

The best way to handle things like this depends on
the circumstances. If you tell us what you're trying
to achieve, we may be able to offer advice.

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


Re: Enum questions.

2016-04-13 Thread jmp

On 04/13/2016 12:12 PM, Antoon Pardon wrote:

I have been looking at the enum documentation and it
seems enums are missing two features I rather find
important.

1) Given an Enum value, someway to get the next/previous
one

2) Given two Enum values, iterate over the values between
them.

Did I miss those in the documentation or are they really
missing?



From the doc :

"While Enum and IntEnum are expected to cover the majority of use-cases, 
they cannot cover them all. Here are recipes for some different types of 
enumerations that can be used directly, or as examples for creating 
one’s own."


I would disagree with you when you state that the features you mentioned 
are important. They could be useful, in certain cases but most of your 
code would better be agnostic to the enum value.


Now it is possible that you specifically work with a system where those 
features would be really useful. As mentioned by the documentation, 
subclassing Enum is possible:


tested with python 2.7

from enum import IntEnum

class UltimateEnum(IntEnum):
@classmethod
def range(cls, *args):
enumToVal = lambda e: e.value if isinstance(e, cls) else e
return (i for i in cls if i.value in range(*map(enumToVal, 
args)))

@property
def next(self):
it = iter(self.__class__)
try:
for e in it:
if e is self: return next(it)
except StopIteration:
return None
return None

class Foo(UltimateEnum):
A = 1
B = 4
C = 9
D = 28


print "first to C:"
for f in Foo.range(Foo.C):
print f

print "B to D :"
for f in Foo.range(Foo.B, Foo.D):
print f

print "A to D+1 with step 2 : "
for f in Foo.range(Foo.A, Foo.D.value+1, 2):
print f

print "next property"
print Foo.A.next
print Foo.C.next
print Foo.D.next

In [1]: run test.py
first to C:
Foo.A
Foo.B
B to D :
Foo.B
Foo.C
A to D+1 with step 2 :
Foo.A
Foo.C
next property
Foo.B
Foo.D
None


Hope it helps,

jm

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


Re: Enum questions.

2016-04-13 Thread Michael Selik
On Wed, Apr 13, 2016, 12:14 PM Antoon Pardon 
wrote:

> I have been looking at the enum documentation and it
> seems enums are missing two features I rather find
> important.
>
> 1) Given an Enum value, someway to get the next/previous
>one
>
> 2) Given two Enum values, iterate over the values between
>them.
>
> Did I miss those in the documentation or are they really
> missing?
>

An Enum corresponds to "nominal" data that is coded as a number simply for
storage rather than meaning. If you want next/previous you are thinking of
"ordinal" data which is coded as numbers for the purpose of comparison (but
not arithmetic). Placing nominal data in order would be comparing apples
and oranges, so to speak.

However, IntEnum should give you the features you want.

https://docs.python.org/3/library/enum.html#intenum

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


Re: Enum questions.

2016-04-13 Thread Rustom Mody
On Wednesday, April 13, 2016 at 5:39:13 PM UTC+5:30, Michael Selik wrote:
> On Wed, Apr 13, 2016, 12:14 PM Antoon Pardon
> wrote:
> 
> > I have been looking at the enum documentation and it
> > seems enums are missing two features I rather find
> > important.
> >
> > 1) Given an Enum value, someway to get the next/previous
> >one
> >
> > 2) Given two Enum values, iterate over the values between
> >them.
> >
> > Did I miss those in the documentation or are they really
> > missing?
> >
> 
> An Enum corresponds to "nominal" data that is coded as a number simply for
> storage rather than meaning. If you want next/previous you are thinking of
> "ordinal" data which is coded as numbers for the purpose of comparison (but
> not arithmetic). Placing nominal data in order would be comparing apples
> and oranges, so to speak.
> 
> However, IntEnum should give you the features you want.
> 
> https://docs.python.org/3/library/enum.html#intenum
> 
> >

from enum import Enum
# General (not contiguous) enum
class Color(Enum):
red = 10
blue = 20
green = 30


>>> Color.__members__
OrderedDict([('red', ), ('blue', ), ('green', 
)])

>>> set(Color.__members__)
set(['blue', 'green', 'red'])

>>> {n:Color[n] for n in set(Color.__members__)}
{'blue': , 'green': , 'red': }
>>> 
-- 
https://mail.python.org/mailman/listinfo/python-list


How to XOR a byte output?

2016-04-13 Thread durgadevi1
Hi all, 

I have a doubt regarding a problem.

First, I am required to read a given file.


The output from the file is given below:

b'$//W?\xc0\x829\xa2\xb9\x13\x8c\xd5{\'


I used the type() to identify the class and its a byte class.

I saw many \x and thought it might be hex.


So, I used binascii.hexlify() and got the following output:
b'242f2f573fc08239a2b9138cd57b'

Now, this output is being encrypted and I need to perform an XOR operation on 
it in order to retrieve a secret message.

But, I'm not sure how to code the XOR operation. How do I code that?

Thank you.

PS: I'm not sure if I have done any mistake along the way. That's why I have 
mentioned all the steps that I've done. Let me know if I have done any step 
wrongly. :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to XOR a byte output?

2016-04-13 Thread Chris Angelico
On Wed, Apr 13, 2016 at 11:18 PM, durgadevi1
 wrote:
>
> The output from the file is given below:
>
> b'$//W?\xc0\x829\xa2\xb9\x13\x8c\xd5{\'
>
>
> I used the type() to identify the class and its a byte class.
>
> I saw many \x and thought it might be hex.
>
>
> So, I used binascii.hexlify() and got the following output:
> b'242f2f573fc08239a2b9138cd57b'
>
> Now, this output is being encrypted and I need to perform an XOR operation on 
> it in order to retrieve a secret message.
>
> But, I'm not sure how to code the XOR operation. How do I code that?
>

What you have is a series of bytes. They don't have any obvious
meaning right there, so you're going to have to figure out what to XOR
it with.

Let's just guess that you want to xor with the byte value 0xAA. We can
do that fairly simply, using integer operations.

>>> data = b'$//W?\xc0\x829\xa2\xb9\x13\x8c\xd5{\\'
>>> bytes(b ^ 0xAA for b in data)
b'\x8e\x85\x85\xfd\x95j(\x93\x08\x13\xb9&\x7f\xd1\xf6'

Well, that doesn't look much more intelligible. We can try a few other
byte values pretty easily:

>>> bytes(b ^ 0x17 for b in data)
b'388@(\xd7\x95.\xb5\xae\x04\x9b\xc2lK'
>>> bytes(b ^ 0x9D for b in data)
b'\xb9\xb2\xb2\xca\xa2]\x1f\xa4?$\x8e\x11H\xe6\xc1'
>>> bytes(b ^ 0xE2 for b in data)
b'\xc6\xcd\xcd\xb5\xdd"`\xdb@[\xf1n7\x99\xbe'

but it still doesn't look very promising. You're going to need to know
the key - the byte value, or sequence of byte values, to XOR with.

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


Re: Enum questions.

2016-04-13 Thread Grant Edwards
On 2016-04-13, Michael Selik  wrote:
> On Wed, Apr 13, 2016, 12:14 PM Antoon Pardon  
> wrote:
>
>> I have been looking at the enum documentation and it seems enums
>> are missing two features I rather find important.
>>
>> 1) Given an Enum value, someway to get the next/previous
>>one
>>
>> 2) Given two Enum values, iterate over the values between
>>them.
>>
>> Did I miss those in the documentation or are they really missing?
>
> An Enum corresponds to "nominal" data that is coded as a number
> simply for storage rather than meaning.

FWIW, as an old Pascal programmer, I too would have been surprised
that an "enum" is not ordinal and doesn't support a next/prev and
iteration.

As an old C programmer, not so much. :)

-- 
Grant Edwards   grant.b.edwardsYow! Today, THREE WINOS
  at   from DETROIT sold me a
  gmail.comframed photo of TAB HUNTER
   before his MAKEOVER!

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


Re: How to XOR a byte output?

2016-04-13 Thread durgadevi1
On Wednesday, April 13, 2016 at 9:29:45 PM UTC+8, Chris Angelico wrote:
> On Wed, Apr 13, 2016 at 11:18 PM, durgadevi1
>  wrote:
> >
> > The output from the file is given below:
> >
> > b'$//W?\xc0\x829\xa2\xb9\x13\x8c\xd5{\'
> >
> >
> > I used the type() to identify the class and its a byte class.
> >
> > I saw many \x and thought it might be hex.
> >
> >
> > So, I used binascii.hexlify() and got the following output:
> > b'242f2f573fc08239a2b9138cd57b'
> >
> > Now, this output is being encrypted and I need to perform an XOR operation 
> > on it in order to retrieve a secret message.
> >
> > But, I'm not sure how to code the XOR operation. How do I code that?
> >
> 
> What you have is a series of bytes. They don't have any obvious
> meaning right there, so you're going to have to figure out what to XOR
> it with.
> 
> Let's just guess that you want to xor with the byte value 0xAA. We can
> do that fairly simply, using integer operations.
> 
> >>> data = b'$//W?\xc0\x829\xa2\xb9\x13\x8c\xd5{\\'
> >>> bytes(b ^ 0xAA for b in data)
> b'\x8e\x85\x85\xfd\x95j(\x93\x08\x13\xb9&\x7f\xd1\xf6'
> 
> Well, that doesn't look much more intelligible. We can try a few other
> byte values pretty easily:
> 
> >>> bytes(b ^ 0x17 for b in data)
> b'388@(\xd7\x95.\xb5\xae\x04\x9b\xc2lK'
> >>> bytes(b ^ 0x9D for b in data)
> b'\xb9\xb2\xb2\xca\xa2]\x1f\xa4?$\x8e\x11H\xe6\xc1'
> >>> bytes(b ^ 0xE2 for b in data)
> b'\xc6\xcd\xcd\xb5\xdd"`\xdb@[\xf1n7\x99\xbe'
> 
> but it still doesn't look very promising. You're going to need to know
> the key - the byte value, or sequence of byte values, to XOR with.
> 
> ChrisA

Ok thank you ChrisA. :) 

I would like to check with you whether using binascii.hexlify() to convert the 
series of bytes into alphabets and integers is correct.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Enum questions.

2016-04-13 Thread Marko Rauhamaa
Grant Edwards :

> On 2016-04-13, Michael Selik  wrote:
>> An Enum corresponds to "nominal" data that is coded as a number
>> simply for storage rather than meaning.
>
> FWIW, as an old Pascal programmer, I too would have been surprised
> that an "enum" is not ordinal and doesn't support a next/prev and
> iteration.
>
> As an old C programmer, not so much. :)

>From the Pascal point of view, the "number for storage" seems odd. Why
not:

class Color(enum.Enum):
red = "red"
blue = "blue"
green = "green"

or:

class Color(enum.Enum):
red = object()
blue = object()
green = object()

or:

class Color(enum.Enum):
red
blue
green


This last one is to the point but raises a NameError.


Personally, I have not found enum.Enum all that appealing. If I have
needed such enums in my code, I have usually just defined:

class MyClass:
RED = "RED"
BLUE = "BLUE"
GREEN = "GREEN"


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


Re: Enum questions.

2016-04-13 Thread Ian Kelly
On Wed, Apr 13, 2016 at 7:50 AM, Grant Edwards
 wrote:
> FWIW, as an old Pascal programmer, I too would have been surprised
> that an "enum" is not ordinal and doesn't support a next/prev and
> iteration.

They do support iteration, but it's by order of declaration, not by value.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Enum questions.

2016-04-13 Thread Ethan Furman

On 04/13/2016 07:07 AM, Marko Rauhamaa wrote:


 class Color(enum.Enum):
 red
 blue
 green


This last one is to the point but raises a NameError.


Using the aenum library that last one is possible.  It also has 
NamedConstant and a metaclass-derived NamedTuple! 


--
~Ethan~

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


Re: How to XOR a byte output?

2016-04-13 Thread Marko Rauhamaa
Chris Angelico :

> Let's just guess that you want to xor with the byte value 0xAA. We can
> do that fairly simply, using integer operations.
>
 data = b'$//W?\xc0\x829\xa2\xb9\x13\x8c\xd5{\\'
 bytes(b ^ 0xAA for b in data)
> b'\x8e\x85\x85\xfd\x95j(\x93\x08\x13\xb9&\x7f\xd1\xf6'
>
> Well, that doesn't look much more intelligible.

This looks clearer:

   >>> code = b'a0\xed\xf0Z\x15]g^\xce3x'
   >>> key = b')U\x81\x9c55*\x08,\xa2WY'
   >>> bytes(c ^ k for c, k in zip(code, key)).decode()
   'Hello world!'


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


Re: How to XOR a byte output?

2016-04-13 Thread Chris Angelico
On Wed, Apr 13, 2016 at 11:51 PM, durgadevi1
 wrote:
> Ok thank you ChrisA. :)
>
> I would like to check with you whether using binascii.hexlify() to convert 
> the series of bytes into alphabets and integers is correct.

It converts the bytes (which are small integers) into the hexadecimal
representation of them (which is digits 0-9 and A-F or a-f). It's
often the easiest way to see what the byte values *are*, but it
doesn't help you much with figuring out what they *mean*.

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


Re: Advice on Python build tools

2016-04-13 Thread Chris Warrick
On 12 April 2016 at 11:48, Sayth Renshaw  wrote:
> Hi
>
> Looking at the wiki list of build tools
> https://wiki.python.org/moin/ConfigurationAndBuildTools
>
> Has anyone much experience in build tools as i have no preference or 
> experience to lean on.
>
> Off descriptions only i would choose invoke.
>
> My requirements, simply i want to learn and build a simple static website 
> generator. Many i am not liking design of or are overkill so its a good 
> opportunity to learn, logya is a good starting point for what i think a good 
> python static generator should be.
>
> Second i want to use Jade templates (js) as i think they are more pythonic 
> than jinja and mako so being able to have mixed js and python support would 
> be needed.
>
> Thoughts?
>
> Sayth
> --
> https://mail.python.org/mailman/listinfo/python-list

Here’s a great static site generator (disclaimer, I’m a core dev over there):

https://getnikola.com/

We use doit, which is on that list. With doit, we get an existing
build system, and incremental rebuilds — for free. I recommend you try
Nikola, and if you don’t like it and still want to build something
yourself, doit is going to be a great way to do it. That said,
incremental builds often involve trial-and-error and subtle bugs when
you start working on it. And if you don’t like doit, you can always
write your own build micro-system. Because if you want to write
something simple and minimal, an existing large build system will just
make things harder.

As for Jade templates, you can’t do that reasonably. You would need to
produce some hack to spawn a JavaScript subprocess, and it would limit
what you can use in templates. Instead, look for a template system
that is written in Python and that has similar syntax.

(also, I wouldn’t consider such weird-thing-into-real-HTML template
engines pythonic)

-- 
Chris Warrick 
PGP: 5EAAEA16
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to XOR a byte output?

2016-04-13 Thread Ian Kelly
On Wed, Apr 13, 2016 at 8:27 AM, Marko Rauhamaa  wrote:
> Chris Angelico :
>
>> Let's just guess that you want to xor with the byte value 0xAA. We can
>> do that fairly simply, using integer operations.
>>
> data = b'$//W?\xc0\x829\xa2\xb9\x13\x8c\xd5{\\'
> bytes(b ^ 0xAA for b in data)
>> b'\x8e\x85\x85\xfd\x95j(\x93\x08\x13\xb9&\x7f\xd1\xf6'
>>
>> Well, that doesn't look much more intelligible.
>
> This looks clearer:
>
>>>> code = b'a0\xed\xf0Z\x15]g^\xce3x'
>>>> key = b')U\x81\x9c55*\x08,\xa2WY'
>>>> bytes(c ^ k for c, k in zip(code, key)).decode()
>'Hello world!'

But that's not the code from the OP's post. The solution is obviously this:

>>> code = b'$//W?\xc0\x829\xa2\xb9\x13\x8c\xd5{'
>>> key = b'm\x0fC8I\xa5\xa2i\xdb\xcd{\xe3\xbbZ'
>>> bytes(c ^ k for c, k in zip(code, key)).decode()
'I love Python!'
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to XOR a byte output?

2016-04-13 Thread Stephen Hansen
On Wed, Apr 13, 2016, at 06:51 AM, durgadevi1 wrote:
> I would like to check with you whether using binascii.hexlify() to
> convert the series of bytes into alphabets and integers is correct.

To be clear, they already are integers.The \x notation is how you
naively represent a byte out of the printable range in ASCII. A byte is
a number from 0 to 255, which can also be thought of as 0x00 to 0xFF..
The 'printable range' is those bytes which represent normal characters
instead of control codes and such.

Computers like showing raw byte data in hex \x (which shouldn't be
confused with binascii.hexify) because then each byte concisely fills up
exactly 2 (well, 4, counting the \x) characters, instead of some bytes
being only one character (1), some being two (10), and some being three
(100).

You can see the integer value, consider:

>>> data = b'$//W?\xc0\x829\xa2\xb9\x13\x8c\xd5{\\'
>>> print data[0]
36
>>> print data[10]
19
>>> list(data)
[36, 47, 47, 87, 63, 192, 130, 57, 162, 185, 19, 140, 213, 123, 92]

binascii is almost certainly not what you want: that converts arbitrary
bytes into an ASCII encoded string, at which point its no longer bytes
(and before you did something to it besides displaying it, you'd want to
decode it back to bytes again, probably).

--Stephen
m e @ i x o k a i . i o
-- 
https://mail.python.org/mailman/listinfo/python-list


IdentationError; unexpected indent

2016-04-13 Thread salma ammar
Hi,

I am about to run this code using python 2.7. But when executing this code,
an error appears (see attachement): IdentationError; unexpected indent

What should I rectify to correct this error please?


*import sys*
*sys.path.append('C:/Users/user/src/sumo-0.22.0/tools')*
*import sumolib*
*net =
sumolib.net.readNet("C:/Users/user/src/sumo-0.22.0/tools/sumolib/net/qgislyonvelo.net.xml")*
*radius = 0*
*f = open("C:/fichierstations.txt", "r")*

*contenu = f.read()*

*print(contenu)*
*for id, lat, lon in f:*
*x, y = net.convertLonLat2XY(lon, lat)*
*print(x, y)*
*edges = net.getNeighboringEdges(x, y, radius)*
*print (edges)*
*while len(edges) == 0:*
*radius = radius + 10*
*  edges = net.getNeighboringEdges(x, y, radius)*
* distancesAndEdges = sorted([(dist, edge) for edge, dist in edges])*
*  print(distancesAndEdges)*
*edgeofstation[id] = distancesAndEdges[0]*
*print (edgeofstation[id])*
*f.close()*


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


Re: IdentationError; unexpected indent

2016-04-13 Thread alister
On Wed, 13 Apr 2016 16:53:09 +0100, salma ammar wrote:

> Hi,
> 
> I am about to run this code using python 2.7. But when executing this
> code,
> an error appears (see attachement): IdentationError; unexpected indent
> 
> What should I rectify to correct this error please?
> 
> 
> *import sys*
> *sys.path.append('C:/Users/user/src/sumo-0.22.0/tools')*
> *import sumolib*
> *net =
> sumolib.net.readNet("C:/Users/user/src/sumo-0.22.0/tools/sumolib/net/
qgislyonvelo.net.xml")*
> *radius = 0*
> *f = open("C:/fichierstations.txt", "r")*
> 
> *contenu = f.read()*
> 
> *print(contenu)*
> *for id, lat, lon in f:*
> *x, y = net.convertLonLat2XY(lon, lat)*
> *print(x, y)*
> *edges = net.getNeighboringEdges(x, y, radius)*
> *print (edges)*
> *while len(edges) == 0:*
> *radius = radius + 10*
> *  edges = net.getNeighboringEdges(x, y, radius)*
> * distancesAndEdges = sorted([(dist, edge) for edge, dist in edges])*
> *  print(distancesAndEdges)*
> *edgeofstation[id] = distancesAndEdges[0]*
> *print (edgeofstation[id])*
> *f.close()*
> 
> 
> Thank you in advance.

correct the indentation for the line that is listed in the traceback
(this may possibly be due to mixing tabs and spaces)

for more detailed help please post a usable copy of the code (without the 
leading & trailing '8' characters on each line) and a full copy of the 
traceback






-- 
I brought my BOWLING BALL -- and some DRUGS!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: IdentationError; unexpected indent

2016-04-13 Thread Igor Korot
Hi, Salma,

On Wed, Apr 13, 2016 at 11:53 AM, salma ammar  wrote:
> Hi,
>
> I am about to run this code using python 2.7. But when executing this code,
> an error appears (see attachement): IdentationError; unexpected indent
>
> What should I rectify to correct this error please?
>
>
> *import sys*
> *sys.path.append('C:/Users/user/src/sumo-0.22.0/tools')*
> *import sumolib*
> *net =
> sumolib.net.readNet("C:/Users/user/src/sumo-0.22.0/tools/sumolib/net/qgislyonvelo.net.xml")*
> *radius = 0*
> *f = open("C:/fichierstations.txt", "r")*
>
> *contenu = f.read()*
>
> *print(contenu)*
> *for id, lat, lon in f:*
> *x, y = net.convertLonLat2XY(lon, lat)*
> *print(x, y)*
> *edges = net.getNeighboringEdges(x, y, radius)*
> *print (edges)*
> *while len(edges) == 0:*
> *radius = radius + 10*
> *  edges = net.getNeighboringEdges(x, y, radius)*
> * distancesAndEdges = sorted([(dist, edge) for edge, dist in edges])*
> *  print(distancesAndEdges)*
> *edgeofstation[id] = distancesAndEdges[0]*
> *print (edgeofstation[id])*
> *f.close()*

What are those '*' symbols in the e-mails?
Are they hard tabs or something else?

Please copy and paste the script from the editor.

Thank you.

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


Re: IdentationError; unexpected indent

2016-04-13 Thread Ian Kelly
On Wed, Apr 13, 2016 at 9:53 AM, salma ammar  wrote:
> Hi,
>
> I am about to run this code using python 2.7. But when executing this code,
> an error appears (see attachement): IdentationError; unexpected indent
>
> What should I rectify to correct this error please?

First of all, please post your code exactly as you're trying to run
it. All those asterisks make it harder to read and also create doubts
about what other changes might have been introduced in the process of
being posted.

Second, read the error message. It tells you what the problem is:
unexpected indent. It should also tell you exactly line the error
occurs on, but you didn't include that part of the error message in
your post, so we can't help you there. Next time, please post the
entire error message, including the traceback.

> *  edges = net.getNeighboringEdges(x, y, radius)*
> * distancesAndEdges = sorted([(dist, edge) for edge, dist in edges])*
> *  print(distancesAndEdges)*
> *edgeofstation[id] = distancesAndEdges[0]*
> *print (edgeofstation[id])*

That said, these five lines all appear to have inconsistent
indentation with the preceding. I don't know what the intent was, but
you should correct the indentation of these lines.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: IdentationError; unexpected indent

2016-04-13 Thread Rob Gaddi
salma ammar wrote:

> Hi,
>
> I am about to run this code using python 2.7. But when executing this code,
> an error appears (see attachement): IdentationError; unexpected indent
>
> What should I rectify to correct this error please?
>
>
> *import sys*
> *sys.path.append('C:/Users/user/src/sumo-0.22.0/tools')*
> *import sumolib*
> *net =
> sumolib.net.readNet("C:/Users/user/src/sumo-0.22.0/tools/sumolib/net/qgislyonvelo.net.xml")*
> *radius = 0*
> *f = open("C:/fichierstations.txt", "r")*
>
> *contenu = f.read()*
>
> *print(contenu)*
> *for id, lat, lon in f:*
> *x, y = net.convertLonLat2XY(lon, lat)*
> *print(x, y)*
> *edges = net.getNeighboringEdges(x, y, radius)*
> *print (edges)*
> *while len(edges) == 0:*
> *radius = radius + 10*
> *  edges = net.getNeighboringEdges(x, y, radius)*
> * distancesAndEdges = sorted([(dist, edge) for edge, dist in edges])*
> *  print(distancesAndEdges)*
> *edgeofstation[id] = distancesAndEdges[0]*
> *print (edgeofstation[id])*
> *f.close()*
>
>
> Thank you in advance.

Offhand, I'd say you should fix the error in your indentation, probably
at the line number that the error specifies.

Python cares about indentation, and uses it the way other languages use
braces.  Things that are at the same logical depth must be indented the
same way.  That includes the difference between tabs and spaces, which
you should NEVER EVER EVER mix and match.

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to XOR a byte output?

2016-04-13 Thread alister
On Wed, 13 Apr 2016 06:18:22 -0700, durgadevi1 wrote:

> Hi all,
> 
> I have a doubt regarding a problem.
> 
No, you have a question doubt means you don't believe something
(sorry I know this is not an English language lesson)
 
> First, I am required to read a given file.
> 
> 
> The output from the file is given below:
> 
> b'$//W?\xc0\x829\xa2\xb9\x13\x8c\xd5{\'
> 
> 
> I used the type() to identify the class and its a byte class.
> 
correct  it is a string o bytes & bytes that do not have a dispalyable 
ASCI character are shown using the \x format
> I saw many \x and thought it might be hex.
> 
> 
> So, I used binascii.hexlify() and got the following output:
> b'242f2f573fc08239a2b9138cd57b'
> 
> Now, this output is being encrypted and I need to perform an XOR
> operation on it in order to retrieve a secret message.
> 
No you ned to perform the Xor operation on the original bytes hexifying 
the string will not help you (it will actual make the situation worse)

> But, I'm not sure how to code the XOR operation. How do I code that?

without completing your homework for you, the principle is

step through each byte in turn
perform the XOR function 
add the result to a new byte string.

if  you are using the correct xor value hopefully you will get a readable 
output.

> 
> Thank you.
> 
> PS: I'm not sure if I have done any mistake along the way. That's why I
> have mentioned all the steps that I've done. Let me know if I have done
> any step wrongly. :)

indeed this has been better written than most homework assistance 
requests posted here that simply want a solution, but mentioning it is 
homework would be better still.




-- 
Don't let your status become too quo!
-- 
https://mail.python.org/mailman/listinfo/python-list


English dialect (Was: How to XOR a byte output?)

2016-04-13 Thread Ian Kelly
On Wed, Apr 13, 2016 at 10:15 AM, alister  wrote:
> On Wed, 13 Apr 2016 06:18:22 -0700, durgadevi1 wrote:
>
>> Hi all,
>>
>> I have a doubt regarding a problem.
>>
> No, you have a question doubt means you don't believe something
> (sorry I know this is not an English language lesson)

No, this is a difference in dialect.

http://www.amritt.com/india-english-dictionary/?term=doubt

That it's not used this way in other parts of the English-speaking
world does not make it any more incorrect than Americans referring to
chips as "french fries".
-- 
https://mail.python.org/mailman/listinfo/python-list


sum accuracy

2016-04-13 Thread Robin Becker
Does anyone know if sum does anything special to try and improve accuracy? My 
simple tests seem to show it is exactly equivalent to a for loop summation.

--
Robin Becker

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


[OT] A doubt about a doubt, was Re: How to XOR a byte output?

2016-04-13 Thread Peter Otten
alister wrote:

> On Wed, 13 Apr 2016 06:18:22 -0700, durgadevi1 wrote:
> 
>> I have a doubt regarding a problem.
>> 
> No, you have a question doubt means you don't believe something
> (sorry I know this is not an English language lesson)

"doubt" is commonly used that way in Indian English, see

http://english.stackexchange.com/questions/2429/can-doubt-sometimes-mean-question


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


Re: sum accuracy

2016-04-13 Thread Random832
On Wed, Apr 13, 2016, at 12:51, Robin Becker wrote:
> Does anyone know if sum does anything special to try and improve
> accuracy? My 
> simple tests seem to show it is exactly equivalent to a for loop
> summation.

No, it doesn't. Sum works on any type that can be added (except
strings), it can't make any assumptions about the characteristics of
floating point types. For non-numeric types, the addition operator may
not be semantically commutative or associative.

Look at
http://code.activestate.com/recipes/393090-binary-floating-point-summation-accurate-to-full-p/
for an example of a more accurate algorithm, but note that, for example,
this algorithm wouldn't work on complex numbers (you'd have to sum the
real and imaginary components separately)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: sum accuracy

2016-04-13 Thread Jussi Piitulainen
Robin Becker writes:

> Does anyone know if sum does anything special to try and improve
> accuracy? My simple tests seem to show it is exactly equivalent to a
> for loop summation.

You want math.fsum.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: sum accuracy

2016-04-13 Thread Peter Otten
Robin Becker wrote:

> Does anyone know if sum does anything special to try and improve accuracy?
> My simple tests seem to show it is exactly equivalent to a for loop
> summation.

If you are worried about accuracy and your values are floating point numbers 
use math.fsum():

"""
fsum(...)
fsum(iterable)

Return an accurate floating point sum of values in the iterable.
Assumes IEEE-754 floating point arithmetic.
"""

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


Re: hourly weather forecast data

2016-04-13 Thread Hasan Diwan
On 2016-04-13, Stephen Hansen  wrote:
> On Tue, Apr 12, 2016, at 08:36 PM, kamaraju kusumanchi wrote:
>> Is there a way to get hourly weather forecast data (temperature,
>> chance of precipitation) from the command line in Debian Linux?
>
> Personally, the last time I wanted to do something like this, I used the
> requests library to fetch a RSS feed from Wunderground. But that was
> awhile ago and I don't see the obvious RSS links banymore.
>
> Did you see: https://www.wunderground.com/weather/api/d/docs

rssweather.com is the site to get RSS feeds for weather.
-- 
https://mail.python.org/mailman/listinfo/python-list


Append/Replace a row in a pandas DataFrame

2016-04-13 Thread Paulo da Silva
Hi all.
I am learning pandas DataFrame and I want to add (eventually replace by
index) some rows.
For adding here is what I tried:

>df = pd.DataFrame(np.random.randn(6,4), index=dates, columns=list('ABCD'))

>df
   A B C D
2013-01-01 -0.111621  1.126761 -2.420517  0.660948
2013-01-02 -0.243397 -0.975684 -0.679209 -0.656913
2013-01-03  0.405816  0.478353  0.621906 -0.262615
2013-01-04 -0.380249  0.416711 -0.906286  1.828339
2013-01-05  0.772747  0.993784  0.452746  1.665306
2013-01-06  0.535011 -0.662874  1.504281  0.543537

[6 rows x 4 columns]

>dft=pd.DataFrame([[1,2,3,4]],
index=[datetime.date(2016,1,12)],columns=df.columns)

>dft
A  B  C  D
2016-01-12  1  2  3  4

[1 rows x 4 columns]

>pd.concat([df,dft])
Out[71]:
A B C D
2013-01-01 00:00:00 -0.111621  1.126761 -2.420517  0.660948
2013-01-02 00:00:00 -0.243397 -0.975684 -0.679209 -0.656913
2013-01-03 00:00:00  0.405816  0.478353  0.621906 -0.262615
2013-01-04 00:00:00 -0.380249  0.416711 -0.906286  1.828339
2013-01-05 00:00:00  0.772747  0.993784  0.452746  1.665306
2013-01-06 00:00:00  0.535011 -0.662874  1.504281  0.543537
2016-01-12   1.00  2.00  3.00  4.00

[7 rows x 4 columns]

Why am I getting the second column?!

How do I do to have a row replaced instead of added if its date (index)
is an existent one?

Thanks for any help or comments.
Paulo
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Enum questions.

2016-04-13 Thread Ethan Furman

On 04/13/2016 07:21 AM, Ethan Furman wrote:

On 04/13/2016 07:07 AM, Marko Rauhamaa wrote:


 class Color(enum.Enum):
 red
 blue
 green


This last one is to the point but raises a NameError.


Using the aenum library that last one is possible.  It also has
NamedConstant and a metaclass-derived NamedTuple! 


Oh, and to keep it mostly safe, the magic that creates the missing names 
is turned off as soon as something real happens, like creating a 
property or a method.


--
~Ethan~

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


Re: real time FM synthesizer

2016-04-13 Thread Irmen de Jong
On 13-4-2016 10:41, jkn wrote:
> Hi Irmen
> 
> On Wednesday, April 13, 2016 at 12:22:25 AM UTC+1, Irmen de Jong wrote:
>> It seems that Python is fast enough [1] to create a real time FM music 
>> synthesizer
>> (think Yamaha DX-7). I made one that you can see here:
>>   https://github.com/irmen/synthesizer
>>
[...]
> 
> This looks fantastic - I am sure I can have a lot of fun with this. Thanks 
> for publicising.

Happy to hear you like it.
I made a few small gui updates tonight.

I think I'll let it rest for a while now but I still have two ideas I might add 
in the
future:
- maybe you want to save and load your settings so you can persist your sound 
creations
- it would be nice if you can join the synthesizer with the rhythm pattern 
mixer i.e.
play over a drum loop or something like that.


Irmen

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


Re: Append/Replace a row in a pandas DataFrame [SOLVED]

2016-04-13 Thread Paulo da Silva
Às 21:10 de 13-04-2016, Paulo da Silva escreveu:
> Hi all.
...

> [6 rows x 4 columns]
> 
>> dft=pd.DataFrame([[1,2,3,4]],
> index=[datetime.date(2016,1,12)],columns=df.columns)
> 
>> dft
> A  B  C  D
> 2016-01-12  1  2  3  4
> 
> [1 rows x 4 columns]
> 
>> pd.concat([df,dft])
> Out[71]:
> A B C D
> 2013-01-01 00:00:00 -0.111621  1.126761 -2.420517  0.660948
> 2013-01-02 00:00:00 -0.243397 -0.975684 -0.679209 -0.656913
> 2013-01-03 00:00:00  0.405816  0.478353  0.621906 -0.262615
> 2013-01-04 00:00:00 -0.380249  0.416711 -0.906286  1.828339
> 2013-01-05 00:00:00  0.772747  0.993784  0.452746  1.665306
> 2013-01-06 00:00:00  0.535011 -0.662874  1.504281  0.543537
> 2016-01-12   1.00  2.00  3.00  4.00
> 
> [7 rows x 4 columns]
> 
> Why am I getting the second column?!
I need to use for example pd.datetime instead of datetime.date. In fact
there is no extra col but the inclusion of hour in the index.
Still don't understand why!

> 
> How do I do to have a row replaced instead of added if its date (index)
> is an existent one?
df.loc[]=

Paulo

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


Re: [OT] A doubt about a doubt, was Re: How to XOR a byte output?

2016-04-13 Thread Rustom Mody
On Wednesday, April 13, 2016 at 10:30:07 PM UTC+5:30, Peter Otten wrote:
> alister wrote:
> 
> > On Wed, 13 Apr 2016 06:18:22 -0700, durgadevi1 wrote:
> > 
> >> I have a doubt regarding a problem.
> >> 
> > No, you have a question doubt means you don't believe something
> > (sorry I know this is not an English language lesson)
> 
> "doubt" is commonly used that way in Indian English, see
> 
> http://english.stackexchange.com/questions/2429/can-doubt-sometimes-mean-question

I have a doubt:
Is it incorrect to correct someone when they are incorrect?

[Sprinkle a "politically" on the above to taste ]
-- 
https://mail.python.org/mailman/listinfo/python-list


Looking for feedback on weighted voting algorithm

2016-04-13 Thread justin walters
Hi all,

I'm looking for feedback on the below vote weighting algorithm which
includes sample input. This is written in Python3.

def weight(votes):
"""
Takes a list of tuples in the form of '(vote %, weight)' where vote %
is the
rating that a user gave and weight is the number of votes it counts as.

Returns the average score based on votes and vote weight.
"""

sum_of_votes = 0

num_of_votes = 0

for vote, weight in votes:

sum_of_votes += vote * weight
num_of_votes += weight

score = sum_of_votes/num_of_votes

return score


if __name__ == '__main__':

votes = [(72, 4), (96, 3), (48, 2), (53, 1), (26, 4), (31, 3), (68, 2),
(91, 1)]

print(weight(votes))


Specifically, I'm wondering if this is a good algorithm for weighted
voting. Essentially a vote is weighted by the number of votes it counts as.
I realize that this is an extremely simple algorithm, but I was wondering
if anyone had suggestions on how to improve it. Thank you for your time.
-- 
https://mail.python.org/mailman/listinfo/python-list


Convert input to upper case on screen as it is typed

2016-04-13 Thread Ben Finney
How can my Python program convert the user's keyboard input to upper
case, as though the user has CAPS LOCK enabled?

I want to emulate a program running on a computer which doesn't have any
lower-case letters (i.e. a character set more limited than ASCII).

The text input, typed interactively by the user at the keyboard, should
be forced to upper case in real time as though that's what the user
typed.

The command line interface could use Python's standard ‘cmd’ library, or
something else. The conversion could be done by a custom input stream,
or some other way.

I am not interested in completely re-implementing the
character-by-character input system; for example, I would like to
continue making use of readline if it is available. I only want to
translate the resulting stream as it appears visually and as it comes
into the program.

Especially important is that the interface should appear visibly
indistinguishable from someone actually typing upper case text; the
display should only ever show the user's input as the upper case text
the program will process.

-- 
 \   “It ain't so much the things we don't know that get us in |
  `\trouble. It's the things we know that ain't so.” —Artemus Ward |
_o__) (1834–1867), U.S. journalist |
Ben Finney

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


Re: Convert input to upper case on screen as it is typed

2016-04-13 Thread Dan Sommers
On Thu, 14 Apr 2016 13:25:14 +1000, Ben Finney wrote:

> How can my Python program convert the user's keyboard input to upper
> case, as though the user has CAPS LOCK enabled?

I don't know which OS you're using, but if I run "stty olcuc" in my
Linux shell, then the input driver does that for me.  (Be careful; it's
tricky at that point to "fix" your shell.)

HTH,
Dan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Convert input to upper case on screen as it is typed

2016-04-13 Thread Ben Finney
Dan Sommers  writes:

> On Thu, 14 Apr 2016 13:25:14 +1000, Ben Finney wrote:
>
> > How can my Python program convert the user's keyboard input to upper
> > case, as though the user has CAPS LOCK enabled?
>
> I don't know which OS you're using, but if I run "stty olcuc" in my
> Linux shell, then the input driver does that for me.

Thanks for the suggestion. I need a solution that is specific to the
Python program: it should only affect this program, and should not need
anything special done to the terminal when invoking the program.

-- 
 \“The whole area of [treating source code as intellectual |
  `\property] is almost assuring a customer that you are not going |
_o__)   to do any innovation in the future.” —Gary Barnett |
Ben Finney

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


Re: Convert input to upper case on screen as it is typed

2016-04-13 Thread Gregory Ewing

Ben Finney wrote:

I need a solution that is specific to the
Python program: it should only affect this program, and should not need
anything special done to the terminal when invoking the program.


You might be able to do something with the termios module
to put the tty driver into the appropriate mode.

If you do that, you'll have to be careful to set it back
again before the program exits for any reason, otherwise
your shell session will be messed up.

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


Re: Serious error in int() function?

2016-04-13 Thread ast


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

Hi,

there may be a serious error in python's int() function:

print int(float(2.8/0.1))

yields

27

instead of 28!!

I am using Python Python 2.7.6, GCC 4.8.2 on Linux Ubuntu.

Is that known?
Best,
Martin



I have a similar question, so I post my message here.
Hope this will not annoy the OP


Is it sure that the square root of a square number is always
an integer ?

I would not like to get a result as 345.

from math import sqrt


sqrt(16)

4.0

sqrt(16).is_integer()

True


for n in range(100):

... if not sqrt(n**2).is_integer():
... print(sqrt(n**2))

it seems to work ... but does it work for all integers ?



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