Refactoring in a large code base (was: importing: what does "from" do?)

2016-01-21 Thread Ben Finney
Rustom Mody writes: > You may find this strategy useful: > https://pchiusano.github.io/2015-04-23/unison-update7.html > > particularly the section "Limitations of refactoring via modifying > text files in place, and what to do instead" A direct link to that section is https://pchiusano.github.io

Re: importing: what does "from" do?

2016-01-21 Thread Rustom Mody
On Thursday, January 21, 2016 at 7:53:07 PM UTC+5:30, Charles T. Smith wrote: > What does "from (module) import (func)" do? > > Please don't tell me that I shouldn't ask because real programmers > know not to have circular dependencies ... > > I have no idea what was imported before. I just want

Re: How to simulate C style integer division?

2016-01-21 Thread Random832
Terry Reedy writes: > But fails with remainder 0, as others noted. Lesson: include corner > cases in validation test. Anyway, my main point about writing a clear > spec remains true. My validation test for this was to loop both numerator and denominator from -5 to 5 (skipping denominator 0) to

Re: Installing on linux - missing devel packages

2016-01-21 Thread Frank Millman
On 2016-01-21, Chris Angelico wrote: On Thu, Jan 21, 2016 at 6:18 PM, Frank Millman wrote: Fedora 22 comes standard with Python 3.4.2. I want to install 3.5.1. It is easy enough to download the source and run ./configure;make;make altinstall. But then I find that I cannot import gzip because

Re: How to simulate C style integer division?

2016-01-21 Thread Steven D'Aprano
On Fri, 22 Jan 2016 12:59 pm, Grobu wrote: > On 21/01/16 09:39, Shiyao Ma wrote: >> Hi, >> >> I wanna simulate C style integer division in Python3. >> >> So far what I've got is: >> # a, b = 3, 4 >> >> import math >> result = float(a) / b >> if result > 0: >>result = math.floor(result) >> else

Re: How to simulate C style integer division?

2016-01-21 Thread Terry Reedy
On 1/21/2016 9:56 PM, Terry Reedy wrote: On 1/21/2016 3:39 AM, Shiyao Ma wrote: I wanna simulate C style integer division in Python3. There are two problems with this spec: it assumes that 'C style integer division' is well defined and that we know the definition. Better: "How do I write a

Re: How to simulate C style integer division?

2016-01-21 Thread Terry Reedy
On 1/21/2016 3:39 AM, Shiyao Ma wrote: I wanna simulate C style integer division in Python3. There are two problems with this spec: it assumes that 'C style integer division' is well defined and that we know the definition. Better: "How do I write a function 'div' in Python 3 so that the f

Re: How to simulate C style integer division?

2016-01-21 Thread Grobu
On 21/01/16 09:39, Shiyao Ma wrote: Hi, I wanna simulate C style integer division in Python3. So far what I've got is: # a, b = 3, 4 import math result = float(a) / b if result > 0: result = math.floor(result) else: result = math.ceil(result) I found it's too laborious. Any quick way?

Re: How to simulate C style integer division?

2016-01-21 Thread Matt Wheeler
On 21 January 2016 at 21:17, Marko Rauhamaa wrote: > Well, then there's: > > def intdiv(a, b): > return int(a / b) That depends on how accurate you need it to be >>> def intdiv(a, b): ... return a//b if (a < 0) == (b < 0) else -(-a//b) ... >>> num = 3**171 >>> num 387021023451030799

Re: How to simulate C style integer division?

2016-01-21 Thread Marko Rauhamaa
Random832 : > On Thu, Jan 21, 2016, at 09:31, Marko Rauhamaa wrote: >> Maybe: >> >>def intdiv(a, b): >>return a // b if (a < 0) == (b < 0) else -(-a // b) > > Personally, I like a // b + (a % b and a ^ b < 0) - I've done the > opposite in C to get python-style division. Well, then th

Re: How to simulate C style integer division?

2016-01-21 Thread Random832
On Thu, Jan 21, 2016, at 09:31, Marko Rauhamaa wrote: > Maybe: > >def intdiv(a, b): >return a // b if (a < 0) == (b < 0) else -(-a // b) Personally, I like a // b + (a % b and a ^ b < 0) - I've done the opposite in C to get python-style division. -- https://mail.python.org/mailman/li

Re: How to use the docstring in this property example

2016-01-21 Thread Peter Otten
Robert wrote: > Hi, > > I read below code snippet on link: > https://docs.python.org/2/library/functions.html#property > > -- > class C(object): > def __init__(self): > self._x = None > > def getx(self): > return self._x > > def setx(self, value): >

Re: importing: what does "from" do?

2016-01-21 Thread Charles T. Smith
On Thu, 21 Jan 2016 16:30:30 +, Charles T. Smith wrote: >> Side observation: 'int' is a bad name for a package, because it will >> shadow the name of the 'int' built-in. > > > Boy oh boy have I experienced that now! :) (it wasn't me! ;) ) -- https://mail.python.org/mailman/listinfo/python

Re: importing: what does "from" do?

2016-01-21 Thread Charles T. Smith
On Thu, 21 Jan 2016 08:59:39 -0700, Ian Kelly wrote: > What happens if you just do 'import utilities'. Can you then call > utilities.hexdump? Can you see anything in the utilities module? Yes, that works! That's what I'm doing as a work around. I was trying to avoid doing that because I figured

Re: importing: what does "from" do?

2016-01-21 Thread Steven D'Aprano
On Fri, 22 Jan 2016 02:53 am, Charles T. Smith wrote: > What I need is tools to find the problems. In particular, why doesn't > python give me more of a clue where the problem is? It would be cool > if it would tell me exactly what module to look at, which symbol(s) > were colliding. The proble

Re: importing: what does "from" do?

2016-01-21 Thread Steven D'Aprano
On Fri, 22 Jan 2016 02:12 am, Charles T. Smith wrote: > On Thu, 21 Jan 2016 07:52:17 -0700, Ian Kelly wrote: > >>> I have no idea what was imported before. I just want to import >>> hexdump(). Unfortunately, this does not work: >>> >>> from utilities import hexdump >>> >>> ImportError: can

Re: importing: what does "from" do?

2016-01-21 Thread Ian Kelly
On Thu, Jan 21, 2016 at 8:12 AM, Charles T. Smith wrote: >>> would you explain to me why I get this: >>> >>> (PDB)hexdump(msg) >>> *** NameError: name 'hexdump' is not defined >> >> Probably because the name 'hexdump' is not defined. > > > If indeed it's not defined, then I wouldn't think there'

Re: importing: what does "from" do?

2016-01-21 Thread John Gordon
In "Charles T. Smith" writes: > > How did this error come up? Did the code work previously? If so, what > > changed? > The developers of this legacy code had this as well as other functions > duplicated throughout the system, in order to avoid confronting these > issues. Yes, but did the co

Re: importing: what does "from" do?

2016-01-21 Thread Charles T. Smith
On Thu, 21 Jan 2016 15:44:43 +, John Gordon wrote: > In that case, the problem is most likely a circular import issue, as you > mentioned. The only way to fix it is to reorganize your modules. > > How did this error come up? Did the code work previously? If so, what > changed? What I nee

Re: Single format descriptor for list

2016-01-21 Thread Paul Appleby
Thanks all for the answers. Oscar Benjamin wrote: print(('{}th\n' * len(a)).format(*a)) print(''.join(map('{}th\n'.format, a))) Those two look closest to what I was hoping for, I guess, but as Chris Angelico said, it probably is clearer to just loop over the range. -- https://mail.

Re: Installing on linux - missing devel packages

2016-01-21 Thread Zachary Ware
On Thu, Jan 21, 2016 at 1:18 AM, Frank Millman wrote: > Hi all > > Fedora 22 comes standard with Python 3.4.2. I want to install 3.5.1. > > It is easy enough to download the source and run ./configure;make;make > altinstall. But then I find that I cannot import gzip because zlib-devel is > missing

Re: importing: what does "from" do?

2016-01-21 Thread Charles T. Smith
On Thu, 21 Jan 2016 15:44:43 +, John Gordon wrote: > How did this error come up? Did the code work previously? If so, what > changed? The developers of this legacy code had this as well as other functions duplicated throughout the system, in order to avoid confronting these issues. I'm tr

Re: importing: what does "from" do?

2016-01-21 Thread Charles T. Smith
On Thu, 21 Jan 2016 15:31:45 +, John Gordon wrote: > The most likely explanation here is that the 'utilities' module simply > does not contain something named 'hexdump'. > > Have you inspected the 'utilities' module? Does it, in fact, contain > something named 'hexdump'? Yes -- https://ma

Re: importing: what does "from" do?

2016-01-21 Thread John Gordon
In "Charles T. Smith" writes: > > The most likely explanation here is that the 'utilities' module simply > > does not contain something named 'hexdump'. > > > > Have you inspected the 'utilities' module? Does it, in fact, contain > > something named 'hexdump'? > Yes In that case, the proble

Re: importing: what does "from" do?

2016-01-21 Thread John Gordon
In "Charles T. Smith" writes: > from utilities import hexdump > ImportError: cannot import name hexdump The most likely explanation here is that the 'utilities' module simply does not contain something named 'hexdump'. Have you inspected the 'utilities' module? Does it, in fact, conta

Re: importing: what does "from" do?

2016-01-21 Thread Charles T. Smith
On Thu, 21 Jan 2016 07:52:17 -0700, Ian Kelly wrote: >> I have no idea what was imported before. I just want to import >> hexdump(). Unfortunately, this does not work: >> >> from utilities import hexdump >> >> ImportError: cannot import name hexdump > > What is utilities? Is it a module on

Re: importing: what does "from" do?

2016-01-21 Thread Ian Kelly
On Jan 21, 2016 7:31 AM, "Charles T. Smith" wrote: > > What does "from (module) import (func)" do? Approximately equivalent to: import module func = module.func Except that it doesn't bind "module" to anything. > Please don't tell me that I shouldn't ask because real programmers > know not to

Re: How to simulate C style integer division?

2016-01-21 Thread Jussi Piitulainen
Marko Rauhamaa writes: > Jussi Piitulainen writes: > >> Steven D'Aprano writes: >> >>> So my guess is that the fastest, and certainly the most obvious, way >>> to get the same integer division behaviour as C99 would be: >>> >>> def intdiv(a, b): >>> # C99 style integer division with truncation

Re: Installing on linux - missing devel packages

2016-01-21 Thread Wolfgang Maier
On 1/21/2016 8:27, Chris Angelico wrote: This is a Linux packaging question, more than a Python one. On Debian systems, the way to do that is "apt-get build-dep python3"; check your own package manager for an equivalent - it'll probably be called builddep or similar. Yes, you'd run: dnf buil

Re: Installing on linux - missing devel packages

2016-01-21 Thread Grant Edwards
On 2016-01-21, Chris Angelico wrote: > On Thu, Jan 21, 2016 at 6:18 PM, Frank Millman wrote: >> Fedora 22 comes standard with Python 3.4.2. I want to install 3.5.1. >> >> It is easy enough to download the source and run ./configure;make;make >> altinstall. But then I find that I cannot import gzi

Re: How to simulate C style integer division?

2016-01-21 Thread Marko Rauhamaa
Jussi Piitulainen : > Steven D'Aprano writes: > >> So my guess is that the fastest, and certainly the most obvious, way >> to get the same integer division behaviour as C99 would be: >> >> def intdiv(a, b): >> # C99 style integer division with truncation towards zero. >> n = a//b >> if

importing: what does "from" do?

2016-01-21 Thread Charles T. Smith
What does "from (module) import (func)" do? Please don't tell me that I shouldn't ask because real programmers know not to have circular dependencies ... I have no idea what was imported before. I just want to import hexdump(). Unfortunately, this does not work: from utilities import hexdump

Re: How to simulate C style integer division?

2016-01-21 Thread Wolfgang Maier
On 1/21/2016 15:00, Jussi Piitulainen wrote: Steven D'Aprano writes: So my guess is that the fastest, and certainly the most obvious, way to get the same integer division behaviour as C99 would be: def intdiv(a, b): # C99 style integer division with truncation towards zero. n = a//b

Re: How to simulate C style integer division?

2016-01-21 Thread Jussi Piitulainen
Steven D'Aprano writes: > So my guess is that the fastest, and certainly the most obvious, way > to get the same integer division behaviour as C99 would be: > > def intdiv(a, b): > # C99 style integer division with truncation towards zero. > n = a//b > if (a < 0) != (b < 0): >

Re: How to simulate C style integer division?

2016-01-21 Thread Steven D'Aprano
On Thu, 21 Jan 2016 08:11 pm, Ben Finney wrote: > Shiyao Ma writes: > >> I wanna simulate C style integer division in Python3. > > I'm not sure I know exactly what behaviour you want (“C style” may mean > different things to each of us). Surely is means "whatever the C standard defines integer

Re: Same function but different names with different set of default arguments

2016-01-21 Thread Steven D'Aprano
On Thu, 21 Jan 2016 06:30 pm, Paulo da Silva wrote: > Hi all. > > What is the fastest implementation of the following code? Let's find out. Here are three different ways to do it: def g(p): return def f1(p=3): # argument with a default return g(p) def f2(): # no argument at all

Re: Installing pygame

2016-01-21 Thread jacob Kruger
I literally just installed pyGame under 3.5.1, using following .whl file that pulled off a site offering collections of .whl files: http://www.lfd.uci.edu/~gohlke/pythonlibs/ And, according to following page, the command of pi3p install ...followed by name of .whl file... handled installing pyG

Installing pygame

2016-01-21 Thread John Mycroft
Hi! I have now spent several hours trying to install Pygame with Python 3.5. I have installed from a msi file "successfully" but "import pygame" fails either because Python can't find pygame or because "%1 is not a valid .DLL". I have followed the instructions at https://www.webucator.com/b

Re: How to simulate C style integer division?

2016-01-21 Thread Oscar Benjamin
On 21 January 2016 at 08:39, Shiyao Ma wrote: > > I wanna simulate C style integer division in Python3. > > So far what I've got is: > # a, b = 3, 4 > > import math > result = float(a) / b > if result > 0: > result = math.floor(result) > else: > result = math.ceil(result) > > > I found it's to

Re: How to simulate C style integer division?

2016-01-21 Thread Jussi Piitulainen
Jussi Piitulainen writes: > Shiyao Ma writes: > >> I wanna simulate C style integer division in Python3. >> >> So far what I've got is: >> # a, b = 3, 4 >> >> import math >> result = float(a) / b >> if result > 0: >> result = math.floor(result) >> else: >> result = math.ceil(result) >> >> I fou

Re: How to simulate C style integer division?

2016-01-21 Thread Jussi Piitulainen
Paul Rubin writes: > Ben Finney writes: >> I'm not sure I know exactly what behaviour you want (“C style” may mean >> different things to each of us). > > I thought he meant trunc-division, so -5 / 2 = -2 and -5 % 2 = -1. > Python specifies floor division but C leaves it unspecified, I thought. I

Re: How to simulate C style integer division?

2016-01-21 Thread Paul Rubin
Ben Finney writes: > I'm not sure I know exactly what behaviour you want (“C style” may mean > different things to each of us). I thought he meant trunc-division, so -5 / 2 = -2 and -5 % 2 = -1. Python specifies floor division but C leaves it unspecified, I thought. -- https://mail.python.org/ma

Re: Same function but different names with different set of default arguments

2016-01-21 Thread Peter Otten
Paulo da Silva wrote: > Hi all. > > What is the fastest implementation of the following code? > > def g(p): > ... > return something > > def f1(p="p1"): > return g(p) > > def f2(p="p2"): > return g(p) >>> def g(p): return p.upper() ... >>> def f1(): pass ... >>> f1.__code__ = g.__code__ >>>

Re: How to simulate C style integer division?

2016-01-21 Thread Ben Finney
Shiyao Ma writes: > I wanna simulate C style integer division in Python3. I'm not sure I know exactly what behaviour you want (“C style” may mean different things to each of us). I'll point out that Python's ‘//’ operator specifies floor division https://docs.python.org/3/reference/expressions.

Re: How to simulate C style integer division?

2016-01-21 Thread Jussi Piitulainen
Shiyao Ma writes: > I wanna simulate C style integer division in Python3. > > So far what I've got is: > # a, b = 3, 4 > > import math > result = float(a) / b > if result > 0: > result = math.floor(result) > else: > result = math.ceil(result) > > I found it's too laborious. Any quick way? The

Re: Same function but different names with different set of default arguments

2016-01-21 Thread Yann Kaiser
Apparently the thread poster cannot receive email, I just received a bounce on my previous email :-/ On Thu, Jan 21, 2016, 08:49 Yann Kaiser wrote: > partial treats keyword arguments as default values, though they become > keyword-only as a result : > > f1 = functools.partial(g, p="p1") > > On T

Re: How to simulate C style integer division?

2016-01-21 Thread Peter Heitzer
Shiyao Ma wrote: >Hi, >I wanna simulate C style integer division in Python3. >So far what I've got is: ># a, b = 3, 4 >import math >result = float(a) / b >if result > 0: > result = math.floor(result) >else: > result = math.ceil(result) >I found it's too laborious. Any quick way? In Python3

Re: How to simulate C style integer division?

2016-01-21 Thread Yann Kaiser
You can use the // operator, which should do what you want. On Thu, Jan 21, 2016, 09:40 Shiyao Ma wrote: > Hi, > > I wanna simulate C style integer division in Python3. > > So far what I've got is: > # a, b = 3, 4 > > import math > result = float(a) / b > if result > 0: > result = math.floor(r

Re: Recurring Prompt

2016-01-21 Thread Johannes Findeisen
On Wed, 20 Jan 2016 11:30:19 -0800 Mansi wrote: > Hello, > > I just installed Python 3.5.1 but anytime I use Pycharm, a prompt of whether > I want to modify, repair or uninstall Python keeps on coming up. Even while > I'm in the midst of typing a program. Please advise. I believe, You should

How to simulate C style integer division?

2016-01-21 Thread Shiyao Ma
Hi, I wanna simulate C style integer division in Python3. So far what I've got is: # a, b = 3, 4 import math result = float(a) / b if result > 0: result = math.floor(result) else: result = math.ceil(result) I found it's too laborious. Any quick way? -- 吾輩は猫である。ホームーページはhttps://introo.me