|
If I want to import say just sqrt from numpy I could docode:
But what do I do if I want to import just sqrt but keep the same numpy namespace? code:
The first one works but I'd rather have it called as numpy.sqrt still. The second one doesn't seem to work.
|
# ¿ Nov 30, 2016 11:31 |
|
|
# ¿ Apr 27, 2024 13:18 |
|
Is numpy vs np a religious thing like vim vs emacs? e: I guess if you're forced to 79 characters (lololol what year is this) then that makes sense yeah.
|
# ¿ Nov 30, 2016 22:24 |
|
QuarkJets posted:That's technically correct, which is the best kind of correct. Kind of like how a bicycle is basically a Ferrari, your smart phone is basically a supercomputer, or how genital herpes is basically a cold sore Do you have any good resources for scientific computing with python you could recommend? I'm a scientific computing guy too and until a few months ago I've been working exclusively with Fortran and C. But now I've/we've switched to a new software package that's built on C++ but with python interfaces. I've managed to jump into python and get things running smoothly though the first few weeks were really confusing especially cause even though I "knew" what a class/oop was I didn't really know how to use them. Basically I've been reading a lot of "how to do things the python way" which are okay but I haven't found anything that was more on the lines of "how to do things the python way for fortran programmers with no oop experience."
|
# ¿ Dec 11, 2016 15:55 |
|
QuarkJets posted:Like many/most scientific computing people, I'm self-taught (because even graduate-level scientific computing courses are mostly worthless), so I don't really know of any good resources are for learning OOP with scientific programming. But I'm pretty sure they exist! I'd recommend asking in the scientific/maths computing thread Got any examples for this numpy stuff?
|
# ¿ Dec 17, 2016 15:38 |
|
I'm trying to learn/use Sphinx but I swear every single tutorial I've found is completely worthless and leaves more questions than answers. For example I just want to do something simple like this:code:
Another seemingly simple but difficult thing I want to do is something like: I have a dict with some parameters. I want sphinx to document each key, and I want it to take whatever I already wrote in inline comments. code:
Boris Galerkin fucked around with this message at 00:21 on Dec 22, 2016 |
# ¿ Dec 21, 2016 23:40 |
|
HardDiskD posted:Do you know any OSS project that does what you want in their documentation? I never came across this before. Yes, doxygen lets me do this. For example in fortran syntax, I can do normal comments that won't show up in the auto generated documentation with the normal '!' prefix, but I can also choose to use '!<' and doxygen will include that particular comment line. For my second example, standard fortran doesn't really have dicts so you could use something like a derived type or whatever. code:
And in the documentation it automagically documents each member "key" without me having to copy and paste it and put it all into a docstring.
|
# ¿ Dec 22, 2016 01:28 |
|
accipter posted:Have you taken a look at autodata (need to scroll down to autodata). You can do the following: Hmm ok, will try this again tomorrow. I did some searching and i did see some examples using the "#: etc" syntax and I tried it, but it did nothing. Does "autodata" not get enabled by default? Is being able to explicitly tell sphinx to put this comment line in the documents not a common thing for python developers?
|
# ¿ Dec 22, 2016 01:39 |
|
accipter posted:Usage guidance is really meant to go into the docstring. Comments are there to help the understand the code, and shouldn't really be separated from the code. It's starting to sound like sphinx isn't the right tool for this case then. Not knocking on it, but in this case I don't want to separate usage vs what the code does because the developers are going to be the only users. I want high level information (this function solves df(x)/dx = exp(a(x)*q(x) - 1), where a(x) = ...) but I also want selected comments to appear both in the documentation with latex or latex like rendered math that show what I actually implemented/am solving since the actual equation implemented might not resemble the one in the docstring, and for it to appear in the code next to the relevant lines.
|
# ¿ Dec 22, 2016 06:07 |
|
accipter posted:You can definitely make Sphinx work for what you want to do, but it isn't standard practice. The biggest issue that I see with what you are trying to do is that including a # comment in the documentation seems worthless to me without the code associated with that comment. If you agree, then it would be easy to include links to highlighted source code using sphinx.ext.viewcode. This would allow a user to browse the API and readily access the source code to see implementation. If you are set on including some # comments within the generated documentation that is possible with Sphinx and how you accomplish that depends on how you are generating the documentation. If you are using autodoc and/or autosummary, you need to modify the templates to include the autodata field. This would take about 10 minutes to modify the templates. I do agree and that viewcode extension looks like it might work out. I'll give it a shot thanks. BigRedDot posted:Anyway, it sort of sounds like you are looking for a "literate programming" tool for Python. If that's the case you might find Pycco more suited. That seems way too verbose without looking into the configuration. I'm going to give the viewcode extension a shot. Unrelated question, tell me if I'm doing this wrong: I have a module called message_tools.py that contains some functions for, well, messaging/output. Is it wrong to add this to my __init__.py? code:
e: I made a setup.py for this package and got it working smoothly, except that the PKG INFO file says 'PLATFORM: UNKNOWN'. I tried adding the classifier for OS :: POSIX :: Linux but that didn't change the PLATFORM string. What do I need to add to fix that? Boris Galerkin fucked around with this message at 23:15 on Dec 23, 2016 |
# ¿ Dec 23, 2016 23:13 |
|
I'm documenting some tutorials/examples with Sphinx and for each tutorial (it's a python module/script) I'm writing the documentation at the module level docstring and then using automodule in my docs/source directory to get it generated. I want to include the actual code into the HTML page that gets generated. How do I do that? I tried with 'literalinclude' but this, well, literally includes also its docstring which I don't want. I guess I could just specify which lines to include but it would be better if it would automatically just include everything below the module level docstring. Secondly is there a variable I can tell the docstring to include itself (with its path automatically expanded)? Right now I have to do "literalinclude: ../../tutorials/.." and so on. I'd like to just do something like "literalinclude: $SELF".
|
# ¿ Feb 8, 2017 14:45 |
|
VikingofRock posted:Hey so what's the state of the art way of doing packaging? I want something where I can run some command(s) on the command line and it'll download all the right dependencies for my script, download the right version of python, and run the script. But it seems like there are a million different tools that each do a part of this and it's not really clear to me how they intersect. I'm not an expert either but I think these two links should help: https://packaging.python.org/distributing/ https://github.com/pypa/sampleproject If you clone the sampleproject you should be able to customize it to your own package and then just run a pip install . from your project directory. You should be able to configure it to download Python dependencies as well. I think if you want to manage non-Python dependencies then you'll have to use Conda/Anaconda, like "download the right version of python." Though I gotta wonder why do you think you need to manage the actual Python installation yourself? That just seems unnecessarily complicated and unless you specifically need to do for whatever reason that then wouldn't it be better off just testing your script against different Python versions? The sampleproject I linked has some scripts/tools that do just that for you, automatically.
|
# ¿ Feb 10, 2017 09:55 |
|
I wanna use virtualenv like all the cool kids but one of the python packages/libraries I'm using isn't managed by pip. It's something I need to compile myself with cmake and is linked against the systemwide Intel MKL and other dependencies. It doesn't show up when I type "pip list" but is importable/usable. How can I use virtualenv --no-site-packages to get a clean environment, but with this one package included/available? Can I just symlink something to my virtualenv folder (and what)?
|
# ¿ Feb 19, 2017 12:37 |
|
Do I use 3 or 4 spaces in my docstrings if I'm using sphinx? e: logging chat: If I use a third party package to build an app, and that third party package has a logger already set up, should I just hook into their logger or should I need to create my own and keep them separated? The info that their logger outputs is useful to me; my extra log messages are just additional things I've added for my app. Boris Galerkin fucked around with this message at 16:01 on Mar 4, 2017 |
# ¿ Mar 4, 2017 11:21 |
|
Thermopyle posted:Create your own logger and logging config. Okay thanks, will do. Another question: I've been trying out pytest and it's really neat. My test codes look much cleaner than with unittest, but what I like the most is the colored red/green output. I do something like TDD so I'm constantly alt-tabbing or tmux pane switching etc to another terminal to re-run tests. Is there already an established way to tell pytest something like "monitor test folder x and re-run your tests every single time source code in folder y changes"? And going further (but maybe too Vim specific) is there a way to have pytest color my vim status bar red/green depending on status so I don't even have to look over to the other terminal unless I need to read the status messages? e: what would be even better is if it would add information to my vim status line, just something short like: "b3,r66; b8,r23", telling me that one test failed in buffer 3 on line 66 so I could just switch my vim buffer directly to "3" and then see which test failed. Boris Galerkin fucked around with this message at 15:34 on Mar 5, 2017 |
# ¿ Mar 5, 2017 15:31 |
|
Should also put in big bold letters at the top when the OP was last updated and keep it updated. IMO the problem with these huge threads/ops is that I click one one and see it posted in 20xx and think "hmm okay I'm just gonna assume everything is outdated."
|
# ¿ Mar 6, 2017 08:08 |
|
|
# ¿ Apr 27, 2024 13:18 |
|
VikingofRock posted:Okay, that's more similar to how I thought it was (I'm also in science academia). Mostly to me it seems like academics use python 2 because that's what's provided by default by Mac OS, CentOS, and Ubuntu, and that's like 99% of what your code is going to be running on. That's my experience as well in academia. Outside of a very narrow group of people and/or field I honestly don't think that academics even know there's a python 2 and python 3, all they know is there is a "python" with numpy and sympy etc and that's that. At the end of the day there's basically only two things that matter: 1) does my code work, and 2) does it run on my laptop and/or hpc cluster. Most people aren't going to care about writing reusable library code to do the things they need to do. They're perfectly fine with one giant script.py file where they manually go in and comment/uncomment out lines of code to run different scripts and such. Either that or old school style script_do_x.py and script_do_x_with_different_y.py, where they are just copies of each other save for some inputs. That's non-CS academia for you.
|
# ¿ Mar 8, 2017 08:25 |