Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I have a bunch of classes I want to rename. Some of them have names that are small and that name is reused in other class names, where I don't want that name changed. Most of this lives in Python code, but we also have some XML code that references class names.
Simple search and replace only gets me so far. In my case, I want to rename AdminAction to AdminActionPlug and AdminActionLogger to AdminActionLoggerPlug, so the first one's search-and-replace would also hit the second, wrongly.
Does anyone have experience with Python refactoring tools ? Bonus points if they can fix class names in the XML documents too.
In the meantime, I've tried it two tools that have some sort of integration with vim.
The first is Rope, a python refactoring library that comes with a Vim (and emacs) plug-in. I tried it for a few renames, and that definitely worked as expected. It allowed me to preview the refactoring as a diff, which is nice. It is a bit text-driven, but that's alright for me, just takes longer to learn.
The second is Bicycle Repair Man which I guess wins points on name. Also plugs into vim and emacs. Haven't played much with it yet, but I remember trying it a long time ago.
Haven't played with both enough yet, or tried more types of refactoring, but I will do some more hacking with them.
I would strongly recommend PyCharm - not just for refactorings. Since the first PyCharm answer was posted here a few years ago the refactoring support in PyCharm has improved significantly.
Python Refactorings available in PyCharm (last checked 2016/07/27 in PyCharm 2016.2)
Change Signature
Convert to Python Package/Module
Copy
Extract Refactorings
Inline
Invert Boolean
Make Top-Level Function
Move Refactorings
Push Members down
Pull Members up
Rename Refactorings
Safe Delete
XML refactorings (I checked in context menu in an XML file):
Rename
Move
Copy
Extract Subquery as CTE
Inline
Javascript refactorings:
Extract Parameter in JavaScript
Change Signature in JavaScript
Extract Variable in JavaScript
WingIDE 4.0 (WingIDE is my python IDE of choice) will support a few refactorings, but I just tried out the latest beta, beta6, and... there's still work to be done. Retract Method works nicely, but Rename Symbol does not.
Update: The 4.0 release has fixed all of the refactoring tools. They work great now.
I would take a look at Bowler (https://pybowler.io).
It's better suited for use directly from the command-line than rope and encourages scripting (one-off scripts).
Your IDE can support refactorings !!
Check it Eric, Eclipse, WingIDE have build in tools for refactorings (Rename including). And that are very safe refactorings - if something can go wrong IDE wont do ref.
Also consider adding few unit test to ensure your code did not suffer during refactorings.
PyCharm have some refactoring features.
PYTHON REFACTORING
Rename refactoring allows to perform global code changes safely and instantly. Local changes within a file are performed in-place. Refactorings work in plain Python and Django projects.
Use Introduce Variable/Field/Constant and Inline Local for improving the code structure within a method, Extract Method to break up longer methods, Extract Superclass, Push Up, Pull Down and Move to move the methods and classes.
You can use sed to perform this. The trick is to recall that regular expressions can recognize word boundaries. This works on all platforms provided you get the tools, which on Windows is Cygwin, Mac OS may require installing the dev tools, I'm not sure, and Linux has this out of the box. So grep, xargs, and sed should do the trick, after 12 hours of reading man pages and trial and error ;)
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I've been using ST2 for quite some time now and given that python is now my primary language, I decided to try PyCharm. It's somewhat cluttered and my love for Sublime is keeping me away. However, PyCharm is somehow able to do the following things which Sublime can't:
Typing a period after an object and getting the CORRECT list of all its attributes (Sublime can do this, sort of, except it returns random attributes)
Refactoring of variables across entire projects/folders
Show docstrings for methods defined with them
It has more important functions which Sublime can't do quite yet. I have many packages already installed in Sublime which can almost do what PyCharm can except for those 3 things above.
So back to the question: How can PyCharm supply this functionality given that Python is not a strongly typed language?
If you're looking for better autocompletion, try SublimeCodeIntel, available via Package Control. It takes a little while to index your built-in modules and third-party packages, but once it's ready it's quite helpful. For example, with Pandas I can define a dataframe:
df = pd.DataFrame(some_input_data)
then type df. and all the associated classes and methods of a DataFrame object come up. To set this up, you'll need to add the following to your user preferences (Preferences -> Settings - User):
"auto_complete_triggers":
[
{
"characters": ".",
"selector": "source"
}
]
along with any other triggers you may have.
UPDATE
While SublimeCodeIntel is a decent package, it doesn't always work well - it sometimes has issues finding newly-installed modules, the database can get corrupted, there can sometimes be significant delays in autocompletion, it has trouble with virtualenvs, and sometimes it just doesn't work. If you're using Sublime Text 3, I highly recommend using Anaconda instead (no relation to the Anaconda Python distribution). Once you set it up (a very brief process, basically you just specify which Python interpreter you'd like to use), it just works. There's no database to initialize or get corrupted, it automatically discovers when you've added new packages, it's very unobtrusive running in the background... I can't say enough good things about it. It uses the JEDI autocompletion module, among other things, and is fast and accurate. It automatically determines what type variables are, and fills in the completions with the appropriate methods and classes that can be called on it. You can have it do parameter completion as well, but that got a little annoying for me, so I turned it off. One thing it can't do is method chaining, but nothing's perfect. It also includes modules for code complexity checking and linting, which is fine, but I don't need it, and only want to lint when I want to lint, so I turned that off as well. The other major difference between it and SublimeCodeIntel is that Anaconda is Python-specific, while SCI supports a number of different languages.
I'd highly recommend giving Anaconda a try. Aside from the method chaining, I've been very happy with it, and haven't gone back. One cool thing you can do is assign different values to the "python_interpreter" setting in your project files, so you can easily use virtualenvs, or (like I do) have one project open for Python 2 coding, and another for Python 3.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I have been programming using Python for slightly more than half an year now and I am more interested in Python internals rather than using Python to develop applications. Currently I am working on porting a few libraries from Python2 to Python3. However, I have a rather abstract view on how to make port stuff over from Python2 to Python3 as most of the changes deal with design issues in Python2.x
I'd like to learn more about Python internals; should I go for a top-down or a bottom-up approach? Are there any references you could recommend?
It sounds like you want to know more about the rationale behind the design of the language, rather than internals. "internals" to me means things like how objects are laid out in memory, how reference counting works, and so on.
If you're looking for a deeper understanding of the design decisions, try reading the PEPs: they are the proposals for changes in the language, and often include detailed discussions of the reasons for the changes, rejected alternatives, and so on. Even the rejected PEPs are useful, because they show the thinking that has shaped the language.
For example:
3105: Making print a function
3110: Catching exceptions in Python 3.x
3131: Supporting non-ASCII identifiers
and so on..
If you really want to learn about Python internals, then start by reading about the Python C API, which is used to build Python itself: my talk A Whirlwind Excursion through Python C Extensions is one place to start. Then you can dive into the Python source code itself for anything you need to learn about.
To someone who is stumbling upon this question from related links or search, there is a documentation written Yaniv Aknin on Python Internals. It starts from the scratch and is highly readable.
I find the series of Yaniv Aknin's Pythons Innards series
fantastic, too
I discovered it thanks to Planet Python
.
You may be also interested by the answer of TryPyPy in this SO thread
I would first read the What's New document for Python 3. It gives a good high-level overview and touches on the detailed changes.
You might also do a search for 'porting to python 3' or similar. There are lots of good resources and tools.
One tool that's new and hard to find is six, by Benjamin Peterson. It enables writing of code that is compatible across the Python 2*3 gap.
The part I found most difficult about maintaining Python 2 and Python 3 -compatible code was deployment. I could write code that would run just fine, but when I went do package and deploy, it was unclear when the conversion should happen. I ultimately found a distutils command build_py_2_to_3 that would do the trick. By using that command in my setup.py, I could release a source distribution that would deploy on either Python 2 or Python 3. An example can be found in jaraco.util.
You also asked about the internals. If you really want to get at the internals, you can view the source for Python 2.x and Python 3.x, though honestly, I would stick with reading the tutorials and maybe some of the .py files in the Python libs.
should I go for a top-down or a bottom-up approach?
Both! Seriously.
Have you tried this?
Automated Python 2 to 3 code
translation
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I've been playing with various ways of doing literate programming in Python. I like noweb, but I have two main problems with it: first, it is hard to build on Windows, where I spend about half my development time; and second, it requires me to indent each chunk of code as it will be in the final program --- which I don't necessarily know when I write it. I don't want to use Leo, because I'm very attached to Emacs.
Is there a good literate programming tool that:
Runs on Windows
Allows me to set the indentation of the chunks when they're used, not when they're written
Still lets me work in Emacs
Thanks!
Correction: noweb does allow me to indent later --- I misread the paper I found on it.
By default, notangle preserves whitespace and maintains indentation when expanding chunks. It can therefore be used with languages like Miranda and Haskell, in which indentation is significant
That leaves me with only the "Runs on Windows" problem.
I have written Pweave http://mpastell.com/pweave, that is aimed for dynamic report generation and uses noweb syntax. It is a pure python script so it also runs on Windows. It doesn't fix your indent problem, but maybe you can modify it for that, the code is really quite simple.
The de-facto standard in the community is IPython notebooks.
Excellent example in which Peter Norvig demonstrates algorithms to solve the Travelling Salesman Problem: https://nbviewer.org/url/norvig.com/ipython/TSP.ipynb
More examples listed at https://github.com/jupyter/jupyter/wiki
I did this:
http://sourceforge.net/projects/pywebtool/
You can get any number of web/weave products that will help you construct a document and code in one swoop.
You can -- pretty easily -- write your own. It's not rocket science to yank the Python code blocks out of RST source and assemble it. Indeed, I suggest you write your own Docutils directives to assemble the Python code from an RST source document.
You run the RST through docutils rst2html (or Sphinx) to produce your final HTML report.
You run your own utility on the same RST source to extract the Python code blocks and produce the final modules.
You could use org-mode and babel-tangle.
That works quite well, since you can give :noweb-ref to source blocks.
Here’s a minimal example: Activate org-babel-tangle, then put this into the file noweb-test.org:
#+begin_src python :exports none :noweb-ref c
abc = "abc"
#+end_src
#+begin_src python :noweb yes :tangle noweb-test.py
def x():
<<c>>
return abc
print(x())
#+end_src
You can also use properties of headlines for giving the noweb-ref. It can then even automatically concatenate several source blocks into one noweb reference.
Add :results output to the #+begin_src line of the second block to see the print results under that block when you hit C-c C-c in the block.
You might find noweb 3 easier to build on Windows. It was designed to be more portable than standard noweb.
Found this tool to be useful: https://github.com/bslatkin/pyliterate
See also my last LP tool: https://code.google.com/archive/p/nano-lp/. It does not requires special input format, supports Markdown/MultiMarkdown, reStructuredText, OpenOffice/LibreOffice, Creole, TeX/LaTeX and has super light and clean syntax - no more cryptic literate programs.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
My company is evaluating the possibility of developing a specialized IDE for Django.
So we would like to ask Django users:
Do you feel the need for a specialized IDE for Django?
Would you be willing to pay for it, or would you only consider free a open-source product?
What Django-specific features are you missing currently in your development tools?
I would pay a reasonable amount for a Django-tailored IDE or plug-in. I don't know what I mean by reasonable, but maye it helps to know that I would not pay more than $75, and I would only pay the $75 if the tool was really awesome.
Now, Django specific features:
Seamless integration with Google Apps
(get me the urchin, the license for
Google Maps, and put it in my
templates)
Full support for the templating engine (details in the other answers you have received)
Lorem ipsum generation (Django has it, just make it simpler)
Prepackaged modules for common tasks (e.g. give me a full login page with template an all)
Link within the code for Django documentation and examples (e.g. Django snippets)
One-click for multi-browser comparison
Full CSS support
An object explorer (along the lines of the Django-admin, but off-line)
A color palette with cool combinations (say, blue-based, orange-based)
Wizard for uploading the local project to Webfaction or similar hosting solution
If I can think of anything else I will edit the answer.
Good luck in designing your product!
I am using Komodo Edit and it's very good. There is a lot of good open-sources product so i don't think that I would buy a commercial product.
Maybe a very good and easy-to-use debugger would make me change my mind.
I hope it helps.
You'll likely want an IDE that will provide you with the ability to do source-level debugging of your accompanying Python code. Without it, your productivity will really be below what it could be.
I use Wing IDE, and I find it to be worth every penny.
I use NotePad++, and have yet to need a fully-fledged IDE specifically for Django (though I do wish NotePad++ would stop periodically crashing).
I wouldn't, unless it was really really good (and I have no idea what features it'd need to make me enthusiastic enough to pay for it).
Maybe a neater way to tie together code for a specific app within a project (models, views and template code). NotePad++'s File->Open dialog is the Windows one, which picks up the directory from the currently open file. It'd be nice if it allowed me to switch quickly between related files.
This question comes up a lot in various forms. I suspect it's because there just isn't a Python IDE which is universally accepted to be awesome.
If I could have:
some of the features of PyDev, like like real code completion, module navigation, live syntax checking and pylint
a fantastic (and fast) text editor (like eric4's scintilla-based editor)
support for django templates (maybe with gui support for wx or glade or whatever),
awesome debugging (like C# on Visual Studio)
a reasonable footprint (i.e., not Eclipse/Aptana or NetBeans)
cross platform (Mac OS X, Linux, and Windows)
sane version control support
auto doctests and unit tests
Then I'd buy it.
All of the python IDEs come close, but all miss the mark by a bit.
(Better yet, it would be open source and I'd download it and donate / contribute to it).
It's great that your company wants to contribute to the community, but I have to say that I don't see what a 'Django IDE' would achieve. There are already plugins for all the main editors and IDEs to support Django - from Vim to TextMate to NetBeans - and these provide syntax highlighting, indentation, shortcuts and snippets for both Python source and Django templates. These can always do with more work, of course, so perhaps your efforts would be best focused on improving one of these.
There are some Django aware IDEs already. PyCharm is excelent for Django development. It even allows to debug Django Templates visually.
graphic models builder to models.py :), I mean this but vice-versa.
yes I will donate.
I would definitely pay or donate for a pure Django IDE, even tho there are already some existing plugins, I feel something is always "floating".
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I noticed that many people here use TextMate for coding on OS X. I've recently started using it, and although I like its minimalistic interface, it makes it harder to stumble upon cool features if you don't know what you're looking for.
So, what feature have you found most helpful for coding (mainly in Python)? Are there any third-party bundles I should know about, besides what's included?
Don't neglect the 'mate' command line tool. You can use it to pipe output into TextMate, so if you do the following...
diff file1.py file2.py | mate
...it will not only open in TextMate, but it is smart enough to know that you're looking at a diff and highlight lines on screen.
TextMate's SVN integration is great; it also seems to have bundles for some other version control systems as well.
Add GetBundle to browse the bundle repository. I found the jQuery bundle through it and it's very handy.
As others have mentioned, rolling your own bundle for frequently used snippets is very helpful. If you have some snippets that are specific to a project or framework, you might want to prefix all of them with a common letter to keep the namespace tidy.
Holding down option while dragging allows you to highlight a block of text. If you type while the highlight is active, your keystrokes appear on multiple lines.
Being able to write simple commands in any scripting language and bind them to a context-specific hotkey.
The Navigation menu commands Go to File (Command + T) and Go to Symbol (Command + Shift + T) are both extremely helpful.
Go to File, which works when you have a project open, lets you type any part of the file name to see only files that match what you've typed.
Go to Symbol has the same type-to-filter interface, but operates on what I'd call the basic block elements of your document. For example, if you're editing a class, Go to Symbol works on the method names, but in a CSS document, you'll be searching on your selectors. It's pretty awesome.
I mention some in a review on Boagworld, I find the snippets, project manager, columnar editing (hold down option while selecting stuff or push it after having selected stuff) and CSS scopes for syntax.
I like the integrated HTML/XML Tidy. Cmd-shift-H is your friend.
Also, nice integration with a variety of scp/sftp clients.
My favourite two features are auto-completion (bound to ⎋ [esc]), and column editing (bound to ⌥ [alt]) both of these things save me quite a lot of time, and are definitely 'robot ninjas'.
The book linked above is also a really useful into to the power of TextMate, although it doesn't specifically mention python.
Don't forget "Drag commands".
They give you the ability to drag, say, an image into a blog.html document and will then upload it to the proper folder and insert the markup for you.
Here is another example of how you can expand further on drag commands if you pair TM up with QuickSilver.
(Disclaimer: I wrote the blog post I linked to there. I still think it's cool though.)
It is worth noting here that there is a Windows alternative to TextMate called E Text Editor. It does pretty much everything TextMate does (apart from macros, but the author is working on this, I think), and even - shock, horror - does some things better, such as the superb bundles editor, the bundles manager, and the branching undo history. Update: and now there's Snippet Pipes.
So, not exactly a useful feature of TextMate as such, but very useful to know if you're a fan of TextMate and you have to use Windows for whatever reason.
The ease of snippet creation.
It's trivial to create new snippets that can accomplish a lot using replacements, tabbing order, and regex substitutions. Quickly assigning these to the tab key for specific languages makes me more productive. And makes me worry about code bloat. :-)
For me the best features are:
Projects - I know every IDE under
the sun has this but TextMate makes
this useful for all sorts of editing
and text processing tasks, and
moreover makes navigating around
these projects easy without ever
lifting your hands from the
keyboard. This is huge for Rails or
Grails projects or large programming
projects with many modules.
The excellent syntax highlighting
and 'snippets' for myriad languages
and tools
The excellent scripting language
support (Being able to evaluate
chunks of Ruby and the like with a
single key chord)
The built in Blogging bundle is
superb. I now use TextMate
exclusively for all my blog posts.
Columnar editing
The ability to use just about any
language or tool to extend TextMate,
Ruby, Perl, shell, name your poison.
An excellent mix of great Aqua GUI
support and excellent command line
support through the
mate and
commands, for
instance making it easy and pleasant
to use TextMate as your default
editor for your SCM.
Using snippets to expand into large, repetitive blocks of code and then using the tab key to move through and only edit the pieces I need to without having to use the mouse or arrow keys.
It's nice and lightweight and has all of the macros built-in for Ruby and let's you run Ruby code, or any other code for that matter just with a keystroke.
Check out ProjectPlus, it gives some useful options for the sidebar, it has SCM status badges for svn and git (though I find the git thing a bit buggy).
I like the fact that it can change the sidebar to an embedded panel on left or right (as opposed to the drawer that's default).
If, like me, you're borderline OCD when it comes to making code look neat, then Option+Cmd+] to line up all the assignments around the current line is awesome!
The mate command line tool is great, you can open an individual file or my favourite use of it is to open a directory of files as a project (e.g. mate .)
Checkout Zen Coding bundle . It gives you an awesome productivity boost to developing both HTML and CSS.