Re: Temporary variables in list comprehensions

2017-01-09 Thread Antonio Caminero Garcia
On Sunday, January 8, 2017 at 7:53:37 PM UTC-8, Steven D'Aprano wrote:
> Suppose you have an expensive calculation that gets used two or more times in 
> a 
> loop. The obvious way to avoid calculating it twice in an ordinary loop is 
> with 
> a temporary variable:
> 
> result = []
> for x in data:
> tmp = expensive_calculation(x)
> result.append((tmp, tmp+1))
> 
> 
> But what if you are using a list comprehension? Alas, list comps don't let 
> you 
> have temporary variables, so you have to write this:
> 
> 
> [(expensive_calculation(x), expensive_calculation(x) + 1) for x in data]
> 
> 
> Or do you? ... no, you don't!
> 
> 
> [(tmp, tmp + 1) for x in data for tmp in [expensive_calculation(x)]]
> 
> 
> I can't decide whether that's an awesome trick or a horrible hack...
> 
> 
> -- 
> Steven
> "Ever since I learned about confirmation bias, I've been seeing 
> it everywhere." - Jon Ronson

Hello I saw some memoizing functions, in that sense you can use the 
functools.lru_cache decorator, that is even better if you have repeated 
elements in data.

@functools.lru_cache
def expensive_calculation(x):
# very NP-hard calculation
pass


Hope that helps :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-08 Thread Antonio Caminero Garcia
On Friday, January 6, 2017 at 6:04:33 AM UTC-8, Peter Otten wrote:
> Example: you are looking for the minimum absolute value in a series of 
> integers. As soon as you encounter the first 0 it's unnecessary extra work 
> to check the remaining values, but the builtin min() will continue.
> 
> The solution is a minimum function that allows the user to specify a stop 
> value:
> 
> >>> from itertools import count, chain
> >>> stopmin(chain(reversed(range(10)), count()), key=abs, stop=0)
> 0
> 
> How would you implement stopmin()?
> 
> Currently I raise an exception in the key function:
> 
> class Stop(Exception):
> pass
> 
> def stopmin(items, key, stop):
> """
> >>> def g():
> ... for i in reversed(range(10)):
> ... print(10*i)
> ... yield str(i)
> >>> stopmin(g(), key=int, stop=5)
> 90
> 80
> 70
> 60
> 50
> '5'
> """
> def key2(value):
> result = key(value)
> if result <= stop:
> raise Stop(value)
> return result
> try:
> return min(items, key=key2)
> except Stop as stop:
> return stop.args[0]

This is the simplest version I could come up with. I also like the classic 100% 
imperative, but it seems that is not trendy between the solutions given :D.

you can test it here https://repl.it/FD5A/0
source code:

from itertools import accumulate

# stopmin calculates the greatest lower bound (infimum). 
# https://upload.wikimedia.org/wikipedia/commons/0/0a/Infimum_illustration.svg 

def takeuntil(pred, seq):
  for item in seq:
yield item
if not pred(item):
  break

def stopmin(seq, stop=0):
  drop_ltstop = (item for item in seq if item >= stop)
  min_gen = (min_ for min_ in accumulate(drop_ltstop, func=min))
  return list(takeuntil(lambda x: x!= stop, min_gen))[-1]

seq = [1, 4, 7, -8, 0, 7, -8, 9] # 0 just until zero is generated
seq = [1, 4, 7, -8, 7, -8, 9] # 1 the entire sequence is generated

print(stopmin(seq, stop=0))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Choosing a Python IDE. what is your Pythonish recommendation? I

2017-01-06 Thread Antonio Caminero Garcia
On Wednesday, January 4, 2017 at 1:10:04 PM UTC-8, Dietmar Schwertberger wrote:
> On 04.01.2017 07:54, Antonio Caminero Garcia wrote:
> > Unfortunately most of the time I am still using print and input functions.
I know that sucks, I did not use the pdb module, I guess that IDE debuggers 
leverage such module.
> pdb is actually quite useful. On my Windows PCs I can invoke python on
> any .py file with the -i command line switch by right clicking in the
> Explorer and selecting "Debug". Now when the script crashes, I can
> inspect variables without launching a full-scale IDE or starting the
> script from the command line. For such quick fixes I have also a context
> menu entry "Edit" for editing with Pythonwin, which is still quite OK as
> editor and has no licensing restrictions or installation requirements.
> This is a nice option when you deploy your installation to many PCs over
> the network.
I am on MacOS but interesting way of debugging, I will take the idea.
>
> For the print functions vs. debugger:
> The most useful application for a debugger like Wing is not for
> bug-fixing, but to set a break point and then interactively develop on
> the debugger console and with the IDE editor's autocompletion using
> introspection on the live objects. This is very helpful for hardware
> interfacing, network protocols or GUI programs. It really boosted my
> productivity in a way I could not believe before. This is something most
> people forget when they evaluate programming languages. It's not the
> language or syntax that counts, but the overall environment. Probably
> the only other really interactive language and environment is Forth.
>
This is exactly part of the capabilities that I am looking for. I loved you 
brought that up. When I think of an ideal IDE (besides the desirable features 
that I already mentioned previously) as a coworker who is telling me the 
values,types and ids that the objects are getting as you are setting 
breakpoints. So why not use the debugger interactively to develop applications. 
As long as one sets the breakpoints in a meaningful way so you can trace your 
code in a very productive way. Is that what you mean by interactive 
environment?

> > If it happens to be Arduino I normally use a sublime plugin called Stino
> > https://github.com/Robot-Will/Stino
> > (1337 people starred that cool number :D)
> Well, it is CodeWarrior which was quite famous at the time of the 68k Macs.
> The company was bought by Motorola and the IDE is still around for
> Freescale/NXP/Qualcomm microcontrollers like the HCS08 8 bit series.
> Around ten years ago the original CodeWarrior IDE was migrated to
> something Eclipse based.
> When I last evaluated HCS08 vs. Arduino, the HCS08 won due to the better
> debug interface and native USB support. HCS08 is still quite cool, but
> when it comes to documentation, learning curve, tools etc. the Arduinos
> win
>
>
> Regards,
>
> Dietmar

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


Re: Choosing a Python IDE. what is your Pythonish recommendation? I

2017-01-06 Thread Antonio Caminero Garcia
On Thursday, January 5, 2017 at 12:32:19 PM UTC-8, fpp wrote:
> > On Thu, Jan 5, 2017 at 12:12 PM, Chris Clark 
> > wrote:
> >> I want an IDE that I can use at work and home, linux and dare I say
> >> windows.
> >> Sublime, had to remove it from my work PC as it is not licensed.
> >> Atom, loved it until it slowed down.
> >> VIM, ok the best if you know vi inside out.
> >> Any JAVA based IDE, just slows up on work PC's due to all the
> >> background stuff that corporates insist they run.
> >> Why can not someone more clever than I fork DrPython and bring it up
> >> to date.
> >> Its is fast, looks great and just does the job ?
>
> I'm suprised no one in this rich thread has even mentioned SciTE :
> http://www.scintilla.org/
>
> Admittedly it's closer to an excellent code editor than a full-blown IDE.
> But it's very lightweight and fast, cross-platform, has superb syntax
> coloring and UTF8 handling, and is highly configurable through its
> configuration file(s) and embedded LUA scripting.
> It's also well maintained : version 1.0 came out in 1999, and the latest
> (3.7.2) is just a week old...
>
> Its IDE side consists mostly of hotkeys to run the interpreter or
> compiler for the language you're editing, with the file in the current
> tab.
> A side pane shows the output (prints, exceptions, errors etc.) of the
> running script.
> A nice touch is that it understands these error messages and makes them
> clickable, taking you to the tab/module/line where the error occurred.
> Also, it can save its current tabs (and their state) to a "session" file
> for later reloading, which is close to the idea of a "project" in most
> IDEs.
> Oh, and it had multi-selection and multi-editing before most of the new
> IDEs out there :-)
>
> Personally that's about all I need for my Python activities, but it can
> be customized much further than I have done : there are "hooks" for other
> external programs than compilers/interpreters, so you can also run a
> linter, debugger or cvs from the editor.
>
> One word of warning: unlike most newer IDEs which tend to be shiny-shiny
> and ful of bells and whistles at first sight, out of the box SciTE is
> *extremely* plain looking (you could even say drab, or ugly :-).
> It is up to you to decide how it should look and what it should do or
> not, through the configuration file.
> Fortunately the documentation is very thorough, and there are a lot of
> examples lying around to be copy/pasted (like a dark theme, LUA scripts
> etc.).
>
> Did I mention it's lightweight ? The archive is about 1.5 MB and it just
> needs unzipping, no installation. May be worth a look if you haven't
> tried it yet...
> fp

Interesting thanks for the link. There are a huge diversity when it comes to 
IDEs/editors. Now I have more than enough options.

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


Re: Choosing a Python IDE. what is your Pythonish recommendation? I

2017-01-06 Thread Antonio Caminero Garcia
On Thursday, January 5, 2017 at 9:51:17 AM UTC-8, ArnoB wrote:
> On 02-01-17 12:38, Antonio Caminero Garcia wrote:
> > Hello, I am having a hard time deciding what IDE or IDE-like code editor
should I use. This can be overwhelming.
> >
> > So far, I have used Vim, Sublime, Atom, Eclipse with PyDev, Pycharm,
IntelliJ with Python plugin.
> >
> > The thing with the from-the-scratch full featured IDEs (Eclipse, IntelliJ,
Pycharm) is that they look like a space craft dashboard and that unwarranted 
resources consumption and the unnecessary icons. I want my IDE to be 
minimalistic but powerful. My screen should be mostly â £made of codeâ Ø as 
usually happens in Vim, Sublime or Atom. However, Pycharm is really cool and 
python oriented.
> >
> > The problem with Vim is the learning curve, so I know the very basic stuff,
but obviously not enough for coding and I do not have time to learn it, it is a 
pity because there are awesome plugins that turns Vim into a lightweight 
powerful IDE-like. So now it is not an option but I will reconsider it in the 
future, learning little by little. Also, I am not very fan GUI guy if the task 
can be accomplished through the terminal. However, I donâ Öt understand why 
people underrate GUIs, that said I normally use shortcuts for the most frequent 
tasks and when I have to do something that is not that frequent then I do it 
with the mouse, for the latter case in vim you would need to look for that 
specific command every time.
> >
> > Sublime is my current and preferred code editor. I installed Anaconda, Git
integration and a couple of additional plugins that make sublime very powerful. 
Also, what I like about sublime compared to the full featured IDEs, besides the 
minimalism, is how you can perform code navigation back and forth so fast, I 
mean this is something that you can also do with the others but for some 
subjective reason I specifically love how sublime does it. The code completion 
in sublime I do not find it very intelligence, the SublimeCodeIntel is better 
than the one that Anaconda uses but the completions are not as verbose as in 
the IDEs.
> >
> > Now, I am thinking about giving a try to Visual Studio Code Edition (take a
look, it sounds good https://marketplace.visualstudio.com/items?itemName=donjay 
amanne.python). I need an editor for professional software development. What 
would you recommend to me?
>
> Hi Antonio,
>
> Just an extra one in case you'll ever want to create
> a nice GUI, then there's also QT Creator:
> https://wiki.qt.io/QtCreator_and_PySide
>
> A very simple but powerful interface a la XCode...
>
> It integrates nicely with PySide:
> https://wiki.qt.io/QtCreator_and_PySide
>
> gr
> Arno

Thanks!

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


Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.

2017-01-06 Thread Antonio Caminero Garcia
On Wednesday, January 4, 2017 at 1:10:04 PM UTC-8, Dietmar Schwertberger wrote:
> On 04.01.2017 07:54, Antonio Caminero Garcia wrote:
> > Unfortunately most of the time I am still using print and input functions. 
> > I know that sucks, I did not use the pdb module, I guess that IDE debuggers 
> > leverage such module.
> pdb is actually quite useful. On my Windows PCs I can invoke python on 
> any .py file with the -i command line switch by right clicking in the 
> Explorer and selecting "Debug". Now when the script crashes, I can 
> inspect variables without launching a full-scale IDE or starting the 
> script from the command line. For such quick fixes I have also a context 
> menu entry "Edit" for editing with Pythonwin, which is still quite OK as 
> editor and has no licensing restrictions or installation requirements. 
> This is a nice option when you deploy your installation to many PCs over 
> the network.
I am on MacOS but interesting way of debugging, I will take the idea.
> 
> For the print functions vs. debugger:
> The most useful application for a debugger like Wing is not for 
> bug-fixing, but to set a break point and then interactively develop on 
> the debugger console and with the IDE editor's autocompletion using 
> introspection on the live objects. This is very helpful for hardware 
> interfacing, network protocols or GUI programs. It really boosted my 
> productivity in a way I could not believe before. This is something most 
> people forget when they evaluate programming languages. It's not the 
> language or syntax that counts, but the overall environment. Probably 
> the only other really interactive language and environment is Forth.
> 
This is exactly part of the capabilities that I am looking for. I loved you 
brought that up. When I think of an ideal IDE (besides the desirable features 
that I already mentioned previously) as a coworker who is telling me the 
values,types and ids that the objects are getting as you are setting 
breakpoints. So why not use the debugger interactively to develop
applications. As long as one sets the breakpoints in a meaningful way so you 
can trace your code in a very productive way. Is that what you mean by 
interactive environment?

> > If it happens to be Arduino I normally use a sublime plugin called Stino
> > https://github.com/Robot-Will/Stino
> > (1337 people starred that cool number :D)
> Well, it is CodeWarrior which was quite famous at the time of the 68k Macs.
> The company was bought by Motorola and the IDE is still around for 
> Freescale/NXP/Qualcomm microcontrollers like the HCS08 8 bit series. 
> Around ten years ago the original CodeWarrior IDE was migrated to 
> something Eclipse based.
> When I last evaluated HCS08 vs. Arduino, the HCS08 won due to the better 
> debug interface and native USB support. HCS08 is still quite cool, but 
> when it comes to documentation, learning curve, tools etc. the Arduinos 
> win
> 
> 
> Regards,
> 
> Dietmar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.

2017-01-06 Thread Antonio Caminero Garcia
On Thursday, January 5, 2017 at 9:51:17 AM UTC-8, ArnoB wrote:
> On 02-01-17 12:38, Antonio Caminero Garcia wrote:
> > Hello, I am having a hard time deciding what IDE or IDE-like code editor 
> > should I use. This can be overwhelming.
> >
> > So far, I have used Vim, Sublime, Atom, Eclipse with PyDev, Pycharm, 
> > IntelliJ with Python plugin.
> >
> > The thing with the from-the-scratch full featured IDEs (Eclipse, IntelliJ, 
> > Pycharm) is that they look like a space craft dashboard and that 
> > unwarranted resources consumption and the unnecessary icons. I want my IDE 
> > to be minimalistic but powerful. My screen should be mostly “made of code” 
> > as usually happens in Vim, Sublime or Atom. However, Pycharm is really cool 
> > and python oriented.
> >
> > The problem with Vim is the learning curve, so I know the very basic stuff, 
> > but obviously not enough for coding and I do not have time to learn it, it 
> > is a pity because there are awesome plugins that turns Vim into a 
> > lightweight powerful IDE-like. So now it is not an option but I will 
> > reconsider it in the future, learning little by little. Also, I am not very 
> > fan GUI guy if the task can be accomplished through the terminal. However, 
> > I don’t understand why people underrate GUIs, that said I normally use 
> > shortcuts for the most frequent tasks and when I have to do something that 
> > is not that frequent then I do it with the mouse, for the latter case in 
> > vim you would need to look for that specific command every time.
> >
> > Sublime is my current and preferred code editor. I installed Anaconda, Git 
> > integration and a couple of additional plugins that make sublime very 
> > powerful. Also, what I like about sublime compared to the full featured 
> > IDEs, besides the minimalism, is how you can perform code navigation back 
> > and forth so fast, I mean this is something that you can also do with the 
> > others but for some subjective reason I specifically love how sublime does 
> > it. The code completion in sublime I do not find it very intelligence, the 
> > SublimeCodeIntel is better than the one that Anaconda uses but the 
> > completions are not as verbose as in the IDEs.
> >
> > Now, I am thinking about giving a try to Visual Studio Code Edition (take a 
> > look, it sounds good 
> > https://marketplace.visualstudio.com/items?itemName=donjayamanne.python). I 
> > need an editor for professional software development. What would you 
> > recommend to me?
> 
> Hi Antonio,
> 
> Just an extra one in case you'll ever want to create
> a nice GUI, then there's also QT Creator:
> https://wiki.qt.io/QtCreator_and_PySide
> 
> A very simple but powerful interface a la XCode...
> 
> It integrates nicely with PySide:
> https://wiki.qt.io/QtCreator_and_PySide
> 
> gr
> Arno

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


Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.

2017-01-06 Thread Antonio Caminero Garcia
On Thursday, January 5, 2017 at 12:32:19 PM UTC-8, fpp wrote:
> > On Thu, Jan 5, 2017 at 12:12 PM, Chris Clark 
> > wrote: 
> >> I want an IDE that I can use at work and home, linux and dare I say
> >> windows.
> >> Sublime, had to remove it from my work PC as it is not licensed.
> >> Atom, loved it until it slowed down.
> >> VIM, ok the best if you know vi inside out.
> >> Any JAVA based IDE, just slows up on work PC's due to all the
> >> background stuff that corporates insist they run.
> >> Why can not someone more clever than I fork DrPython and bring it up
> >> to date.
> >> Its is fast, looks great and just does the job ?
> 
> I'm suprised no one in this rich thread has even mentioned SciTE :
> http://www.scintilla.org/
> 
> Admittedly it's closer to an excellent code editor than a full-blown IDE.
> But it's very lightweight and fast, cross-platform, has superb syntax 
> coloring and UTF8 handling, and is highly configurable through its 
> configuration file(s) and embedded LUA scripting.
> It's also well maintained : version 1.0 came out in 1999, and the latest 
> (3.7.2) is just a week old...
> 
> Its IDE side consists mostly of hotkeys to run the interpreter or 
> compiler for the language you're editing, with the file in the current 
> tab.
> A side pane shows the output (prints, exceptions, errors etc.) of the 
> running script.
> A nice touch is that it understands these error messages and makes them 
> clickable, taking you to the tab/module/line where the error occurred.
> Also, it can save its current tabs (and their state) to a "session" file 
> for later reloading, which is close to the idea of a "project" in most 
> IDEs.
> Oh, and it had multi-selection and multi-editing before most of the new 
> IDEs out there :-)
> 
> Personally that's about all I need for my Python activities, but it can 
> be customized much further than I have done : there are "hooks" for other 
> external programs than compilers/interpreters, so you can also run a 
> linter, debugger or cvs from the editor.
> 
> One word of warning: unlike most newer IDEs which tend to be shiny-shiny 
> and ful of bells and whistles at first sight, out of the box SciTE is 
> *extremely* plain looking (you could even say drab, or ugly :-).
> It is up to you to decide how it should look and what it should do or 
> not, through the configuration file.
> Fortunately the documentation is very thorough, and there are a lot of 
> examples lying around to be copy/pasted (like a dark theme, LUA scripts 
> etc.).
> 
> Did I mention it's lightweight ? The archive is about 1.5 MB and it just 
> needs unzipping, no installation. May be worth a look if you haven't 
> tried it yet...
> fp

Interesting thanks for the link. There are a huge diversity when it comes to 
IDEs/editors. Now I have more than enough options. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Choosing a Python IDE. what is your Pythonish recommendation? I

2017-01-06 Thread Antonio Caminero Garcia
On Tuesday, January 3, 2017 at 4:12:34 PM UTC-8, Dietmar Schwertberger wrote:
> On 02.01.2017 12:38, Antonio Caminero Garcia wrote:
> You did not try Wing IDE? It looks less like a spacecraft. Maybe you
> like it.
> Maybe the difference is that Wing is from Python people while the ones
> you listed are from Java people.

That sounds interesting. By the look of it I think I am going to give it a try.

> For something completely different (microcontroller programming in C) I
> just switched to a Eclipse derived IDE and I don't like it too much as
> the tool does not focus on the problem scope.

If it happens to be Arduino I normally use a sublime plugin called Stino 
https://github.com/Robot-Will/Stino
(1337 people starred that cool number :D)

>  From your posts I'm not sure whether you want an editor or an IDE,
> where for me the main difference is the debugger and code completion.

I want editor with those IDE capabilities and git integration, with optionally 
cool stuff as for example remote debugging.

> I would not want to miss the IDE features any more, even though in my
> first 15 years of Python I thought that a debugger is optional with
> Python ...

Unfortunately most of the time I am still using print and input functions. I 
know that sucks, I did not use the pdb module, I guess that IDE debuggers 
leverage such module.

> Regards,
>
> Dietmar

Thank you so much for your answer.

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


Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.

2017-01-03 Thread Antonio Caminero Garcia
On Tuesday, January 3, 2017 at 4:12:34 PM UTC-8, Dietmar Schwertberger wrote:
> On 02.01.2017 12:38, Antonio Caminero Garcia wrote:
> You did not try Wing IDE? It looks less like a spacecraft. Maybe you 
> like it.
> Maybe the difference is that Wing is from Python people while the ones 
> you listed are from Java people.

That sounds interesting. By the look of it I think I am going to give it a try.

> For something completely different (microcontroller programming in C) I 
> just switched to a Eclipse derived IDE and I don't like it too much as 
> the tool does not focus on the problem scope.

If it happens to be Arduino I normally use a sublime plugin called Stino
https://github.com/Robot-Will/Stino 
(1337 people starred that cool number :D)

>  From your posts I'm not sure whether you want an editor or an IDE, 
> where for me the main difference is the debugger and code completion.

I want editor with those IDE capabilities and git integration, with optionally  
cool stuff as for example remote debugging. 

> I would not want to miss the IDE features any more, even though in my 
> first 15 years of Python I thought that a debugger is optional with 
> Python ...

Unfortunately most of the time I am still using print and input functions. I 
know that sucks, I did not use the pdb module, I guess that IDE debuggers 
leverage such module.

> Regards,
> 
> Dietmar

Thank you so much for your answer. 

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


Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.

2017-01-02 Thread Antonio Caminero Garcia
Guys really thank you for your answers. Basically now I am more emphasizing in 
learning in depth a tool and get stick to it so I can get a fast workflow. 
Eventually I will learn Vim and its python developing setup, I know people who 
have been programming using Vim for almost 20 years and they did not need to 
change editor (that is really awesome). 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.

2017-01-02 Thread Antonio Caminero Garcia
On Monday, January 2, 2017 at 5:57:51 PM UTC-8, Steve D'Aprano wrote:
> On Mon, 2 Jan 2017 10:38 pm, Antonio Caminero Garcia wrote:
> 
> > Hello, I am having a hard time deciding what IDE or IDE-like code editor
> > should I use. This can be overwhelming.
> 
> Linux is my IDE.
> 
> https://sanctum.geek.nz/arabesque/series/unix-as-ide/
> 
> 
> I dislike the Unix-style Vim/Emacs text editors, I prefer a traditional
> GUI-based editor. So my "IDE" is:
> 
> - Firefox, for doing searches and looking up documentation;
> 
> - an GUI programmer's editor, preferably one with a tab-based 
>   interface, such as geany or kate;
> 
> - a tab-based terminal.
> 
> Both geany and kate offer auto-completion based on previously seen words.
> They won't auto-complete function or method signatures, but in my my
> experience this is the "ninety percent" solution: word-based auto-complete
> provides 90% of the auto-complete functionality without the cost of full
> signature-based auto-complete.
> 
> In the terminal, I have at least three tabs open: one open to the Python
> interactive interpreter, for testing code snippets and help(obj); one where
> I run my unit tests ("python -m unittest myproject_tests"); and one where I
> do any assorted other tasks, such as file management, checking code into
> the repo, etc.
> 
> I've played with mypy a few times, but not used it seriously in any
> projects. If I did, I would run that from the command line too, like the
> unit tests. Likewise for any linters or equivalent.
> 
> 
> > So far, I have used Vim, Sublime, Atom, Eclipse with PyDev, Pycharm,
> > IntelliJ with Python plugin.
> > 
> > The thing with the from-the-scratch full featured IDEs (Eclipse, IntelliJ,
> > Pycharm) is that they look like a space craft dashboard and that
> > unwarranted resources consumption and the unnecessary icons. 
> 
> Indeed. If they provide any useful functionality I don't already have, I've
> never come across it. The only thing I'd like to try is an editor that
> offers semantic highlighting instead of syntax highlighting:
> 
> https://medium.com/@evnbr/coding-in-color-3a6db2743a1e
> 
> I once tried Spyder as an IDE, and found that it was so bloated and slow it
> couldn't even keep up with my typing. I'm not even a touch typist! I'd
> start to type a line like:
> 
> except ValueError as err:
> 
> 
> and by the time my fingers were hitting the colon, Spyder was displaying
> `excep` in red flagged with an icon indicating a syntax error.
> 
> 
> 
> 
> -- 
> Steve
> “Cheer up,” they said, “things could be worse.” So I cheered up, and sure
> enough, things got worse.

Thanks for remind the Unix capabilities as IDE, that post was cool to read.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.

2017-01-02 Thread Antonio Caminero Garcia
On Monday, January 2, 2017 at 8:24:29 AM UTC-8, Michael Torrie wrote:
> On 01/02/2017 04:38 AM, Antonio Caminero Garcia wrote:
> > The problem with Vim is the learning curve, so I know the very basic
> > stuff, but obviously not enough for coding and I do not have time to
> > learn it, it is a pity because there are awesome plugins that turns
> > Vim into a lightweight powerful IDE-like. So now it is not an option
> > but I will reconsider it in the future, learning little by little.
> > Also, I am not very fan GUI guy if the task can be accomplished
> > through the terminal. However, I don’t understand why people
> > underrate GUIs, that said I normally use shortcuts for the most
> > frequent tasks and when I have to do something that is not that
> > frequent then I do it with the mouse, for the latter case in vim you
> > would need to look for that specific command every time.
> 
> Really, the basic stuff is enough to be very productive in vim.  In fact
> just knowing how to save and quit is half the battle!  A little cheat
> sheet for vim by your keyboard would be plenty I think.  If all you knew
> was how to change modes, insert, append, change word, yank, delete, and
> paste, that is 99% of what you'd use every day.  You can use normal
> arrow keys, home, end, and page up and page down for cursor movement in
> vim, so even if you can't remember ^,$, gg, or GG, you'll do fine.
> Eventually you can begin to add in other things, like modifiers to c
> (change).
> 
> There probably are a lot of nice plugins for ViM, but I use none of
> them. I just don't find them that useful.  I don't seem to need any IDE
> help with Python.

yeah, for me I think of the IDE (and computers in general must be seen like 
that) as a coworker or as paring programming experience. So I agree I have been 
developing in Python without IDE a long time and I know if I had some features 
borrow from full featured IDEs will definitely   help me out.I will give a try 
to Vim asap, now I am trying Visual Studio now and it seems that is all I want.
-- 
https://mail.python.org/mailman/listinfo/python-list


Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.

2017-01-02 Thread Antonio Caminero Garcia
Hello, I am having a hard time deciding what IDE or IDE-like code editor should 
I use. This can be overwhelming.

So far, I have used Vim, Sublime, Atom, Eclipse with PyDev, Pycharm, IntelliJ 
with Python plugin. 

The thing with the from-the-scratch full featured IDEs (Eclipse, IntelliJ, 
Pycharm) is that they look like a space craft dashboard and that unwarranted 
resources consumption and the unnecessary icons. I want my IDE to be 
minimalistic but powerful. My screen should be mostly “made of code” as usually 
happens in Vim, Sublime or Atom. However, Pycharm is really cool and python 
oriented.

The problem with Vim is the learning curve, so I know the very basic stuff, but 
obviously not enough for coding and I do not have time to learn it, it is a 
pity because there are awesome plugins that turns Vim into a lightweight 
powerful IDE-like. So now it is not an option but I will reconsider it in the 
future, learning little by little. Also, I am not very fan GUI guy if the task 
can be accomplished through the terminal. However, I don’t understand why 
people underrate GUIs, that said I normally use shortcuts for the most frequent 
tasks and when I have to do something that is not that frequent then I do it 
with the mouse, for the latter case in vim you would need to look for that 
specific command every time. 

Sublime is my current and preferred code editor. I installed Anaconda, Git 
integration and a couple of additional plugins that make sublime very powerful. 
Also, what I like about sublime compared to the full featured IDEs, besides the 
minimalism, is how you can perform code navigation back and forth so fast, I 
mean this is something that you can also do with the others but for some 
subjective reason I specifically love how sublime does it. The code completion 
in sublime I do not find it very intelligence, the SublimeCodeIntel is better 
than the one that Anaconda uses but the completions are not as verbose as in 
the IDEs.

Now, I am thinking about giving a try to Visual Studio Code Edition (take a 
look, it sounds good 
https://marketplace.visualstudio.com/items?itemName=donjayamanne.python). I 
need an editor for professional software development. What would you recommend 
to me?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: repeat items in a list

2016-03-29 Thread Antonio Caminero Garcia
On Monday, March 28, 2016 at 11:26:08 PM UTC+2, Chris Angelico wrote:
> On Tue, Mar 29, 2016 at 4:30 AM, Rob Gaddi
>  wrote:
> > beliav...@aol.com wrote:
> >
> >> On Saturday, March 26, 2016 at 7:24:10 PM UTC-4, Erik wrote:
> >>>
> >>> Or, if you want to "import operator" first, you can use 'operator.add'
> >>> instead of the lambda (but you _did_ ask for a one-liner ;)).
> >>>
> >>> Out of interest, why the fascination with one-liners?
> >>
> >> Thanks for your reply. Sometimes when I program in Python I think I am not 
> >> using the full capabilities of the language, so I want to know if there are
> >> more concise ways of doing things.
> >
> > Concise is only worth so much.  PEP20 tells us "Explicit is better than
> > implicit", "Simple is better than complex" and "If the implementation is
> > hard to explain, it's a bad idea".
> >
> > Python is a beautifully expressive language.  Your goal should not be to
> > write the minimum number of lines of code to accomplish the task.
> > Your goal should be to write the code such that your grandmother can
> > understand it.  That way, when you screw it up, you'll be able to easily
> > figure out where and how you did so.  Or failing that, you can get
> > grangran to show you.
> 
> Just out of interest, did you (generic you) happen to notice Mark's
> suggestion? It's a one-liner that nicely expresses the intention and
> accomplishes the goal:
> 
> yy = [aa for aa in xx for _ in range(nrep)]
> 
> It quietly went through without fanfare, but I would say this is the
> perfect solution to the original problem.
> 
> ChrisA

Of course that's definitely the most pythonic sol to this prob :)! Just wanted 
to point out the use of the operator "*" in lists.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: repeat items in a list

2016-03-27 Thread Antonio Caminero Garcia
On Sunday, March 27, 2016 at 11:52:22 AM UTC+2, larudwer wrote:
> how about
> 
>   sorted(["a", "b"]*3)
> ['a', 'a', 'a', 'b', 'b', 'b']

that's cooler, less efficient though and do not maintain the original order. In 
case such order was important, you should proceed as follows:

If the elements are unique, this would work:

sorted(sequence*nrep, key=sequence.index)

Otherwise you'd need a more complex key function (maybe a method of a class 
with a static variable that tracks the number of times that such method is 
called and with a "dynamic index functionality" that acts accordingly (i-th 
nrep-group of value v)) and imo it does not worth it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: repeat items in a list

2016-03-27 Thread Antonio Caminero Garcia
On Sunday, March 27, 2016 at 10:02:44 AM UTC+2, Antonio Caminero Garcia wrote:
> On Saturday, March 26, 2016 at 11:12:58 PM UTC+1, beli...@aol.com wrote:
> > I can create a list that has repeated elements of another list as follows:
> > 
> > xx = ["a","b"]
> > nrep = 3
> > print xx
> > yy = []
> > for aa in xx:
> > for i in range(nrep):
> > yy.append(aa)
> > print yy
> > 
> > output:
> > ['a', 'b']
> > ['a', 'a', 'a', 'b', 'b', 'b']
> > 
> > Is there a one-liner to create a list with repeated elements?
> 
> What about this?
> 
> def rep_elements(sequence, nrep):
> #return [ritem for item in sequence for ritem in [item]*nrep]
> return list(chain.from_iterable(([item]*nrep for item in sequence)))
> 
> sequence = ['h','o','l','a']
> print(rep_elements(sequence,  3))

I prefer the commented solution :).

[ritem for item in sequence for ritem in [item]*nrep] # O(len(sequence)*2nrep) 

and the chain solution  would be # O(len(sequence)*nrep). The constants ate 
gone so I prefer the first one for its readibility.

On a practical level:

https://bpaste.net/show/fe3431a13732
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: repeat items in a list

2016-03-27 Thread Antonio Caminero Garcia
On Saturday, March 26, 2016 at 11:12:58 PM UTC+1, beli...@aol.com wrote:
> I can create a list that has repeated elements of another list as follows:
> 
> xx = ["a","b"]
> nrep = 3
> print xx
> yy = []
> for aa in xx:
> for i in range(nrep):
> yy.append(aa)
> print yy
> 
> output:
> ['a', 'b']
> ['a', 'a', 'a', 'b', 'b', 'b']
> 
> Is there a one-liner to create a list with repeated elements?

What about this?

def rep_elements(sequence, nrep):
#return [ritem for item in sequence for ritem in [item]*nrep]
return list(chain.from_iterable(([item]*nrep for item in sequence)))

sequence = ['h','o','l','a']
print(rep_elements(sequence,  3))
-- 
https://mail.python.org/mailman/listinfo/python-list