|
Fergus Mac Roich posted:So you're finding the smallest difference between any two values in the list, right? As viking_helmet was getting at, your algorithm needs to minimize the number of times it needs to "touch" its elements. Now, your new solution is better than your old one, but step back from it and think: what if you could just know where the num2 value that's most similar to num1 is in the list? There's actually a way to do it, and it's right under your nose. I'll just stick the answer in spoiler tags, because I know I didn't find the fact that this method is faster to be intuitive at first, but you might be smarter than me so make sure to think about it for a bit before looking. I think this is probably a good place to say, you can always check out what you have at your disposal in the objects you're using. Do that in the console using dir(object). So for list type you would do dir(list) and see that sort is one of the list methods. help(list.sort) will pull up the docstring
|
# ¿ Sep 3, 2015 01:25 |
|
|
# ¿ Apr 27, 2024 08:48 |
|
Gothmog1065 posted:Thanks guys! I was overthinking it pretty badly, and after reading flosofl and fergus's hints (I had to cheat), I figured it out pretty drat easily after that. Ended up with this, though I"m sure there's always the way to make it even better (I could probably write it into the first for loop thinking about it just reversing the math signs a bit to save even more time), but this finally got it to work: This is more of a style thing, but I hate having more conditionals than I really need. I'd probably redo it like this. Python code:
Proteus Jones fucked around with this message at 02:14 on Sep 3, 2015 |
# ¿ Sep 3, 2015 02:11 |
|
Hughmoris posted:Any recommended resources for learning OO programming, in Python 3? I've been getting by using basic flow control and conditional statements, and I feel like my development has stalled. If you're willing to spend money, I like Team Treehouse. ($25/mo. or $199/yr) You get access to all the training, so not just Python. Even though I considered myself "intermediate" with the automation I'd do I thought I'd give it a spin for the Data Science course they had. Turns out my poo poo worked out sheer stubbornness. I was a monkey banging the ground with a wrench. I ended up doing their whole Learn Python and I definitely learned I had Been Doing It Wrong. In fact it made crystal clear subjects that had confused and frightened me before like Classes, Methods and Inheritance (I typically wrote brute-force, bulldozer code before). I'm in a much better place programming wise and more confident with my knowledge. In fact with the solid foundation, I find it much easier get up to speed on newer topics. I definitely wouldn't call them advanced courses or really applicable to someone with a really solid mastery in Python, but they're definitely good for the beginning to intermediate programmer. Be aware it is Python 3 they use. I'm a fan and I'm going to be starting the Swift track when I wrap up a project I'm eyeball deep in at work.
|
# ¿ Sep 5, 2015 23:44 |
|
hooah posted:Any suggestions for poorer/cheaper folk? I've done a little codeingame, but it doesn't really require any particular quality of code. I've considered translating some of my C++ projects from school; would this be a decent way to get more familiar with Python's classes? There's this: http://www.diveintopython3.net or this: http://www.python-course.eu/python3_course.php Gothmog1065 posted:Is there another site as good as stack overflow for programming questions? Our work content filter is set up to block access to it right now as "Social Media". Gonna talk to the boss about seeing if networking will allow an exemption to it but it's annoying as poo poo to try to learn crap on my downtime. I'm going to lean toward no. Whenever I google for a coding issue or clarification on an run error usually the 1st page of results is almost all Stack Overflow. The quality of the results taper off sharply after the Stack Overflow. Get them to allow Stack Exchange sites in general ASAP. Proteus Jones fucked around with this message at 21:16 on Sep 7, 2015 |
# ¿ Sep 7, 2015 21:09 |
|
Let's talk VCS. Here's my situation. It's just me and all my projects are local. They're mostly network automation to do same task or tasks thousands of times given a csv file or files of system information. I develop my utilities on a rMBP using PyCharm and I'm using anaconda (python 3.4.3). As background I've just taken a look at one of the first network utilities I've made and I've decided to do a major update to it to make it more flexible and easier on the eyes. What I have been doing is create a new project directory, copying over the old files, and opening the new directory in PyCharm. PyCharm itself tracks a very tiny amount of changes, which has served me OK so far, but if I wander down a wrong path for too long, I realized I have no real recourse other than doing a "poor mans" VCS. i.e. Each time I do a change (other than fixing syntax) I put a version number on the file. This is getting out of control for me. So... what's the recommended method? GitHub is out for now, since I don't want to pay to have "private" projects and there's some stuff that could get me fired if I put it in a public one. But I do have git installed from when I was looking at GitHub. I can also probably get mercurial or others on my box via homebrew if necessary. As an addendum to that question, are there any good tutorials on getting up to speed on VCS? I've never used any before as I'm not really a programmer, but I've started writing more and more Python as part of an automation push that's basically my 20% project at work.
|
# ¿ Sep 8, 2015 03:41 |
|
Fergus Mac Roich posted:You don't need GitHub, you can use Git locally. It sounds like it would pretty much cover your needs with a simple local repository. With a single user, it's surprisingly easy to get everything set up. If you want remote code hosting, try Bitbucket.org, which is free for up to five users for a private repo. Thanks!
|
# ¿ Sep 8, 2015 05:17 |
|
baka kaba posted:PyCharm has Git integration so you get a nice UI and tools right in the IDE I already got it up and running with PyCharm. It's pretty drat pain-free so far. I use time machine so poo poo is backed up, but they all live on a directory mapped to a cloud drive, so I can offload having to worry about both my machine and my local backup being destroyed by catastrophe. Of course, if some happens at that level, I'm sure my utility scripts will be the last thing on my mind. Proteus Jones fucked around with this message at 22:37 on Sep 8, 2015 |
# ¿ Sep 8, 2015 22:33 |
|
Gothmog1065 posted:Do I have to do something more than defining it outside the for loop (Adding it the line above?). That doesn't seem to be fixing anything (even setting the variable outside the while loop), nor does putting the removal into the for loop (which doesn't really do what I want). Put break points in and step through the code to where the value goes wonky. I'd probably set a break point every time disconnect should receive a value and validate it's an expected value. Also stop right before everything blows up and look at what things are vs. what you expect. code:
Actually, I'd probably put all my list initializations at the start of the function. But definitely run it through a debugger. Sorry I misread, you're removing the value of disconnect from link_list. What you're doing is trying to remove a list of tuples from link_list instead of the tuple itself. That will break because link_list[x] is not equal to disconnect. Disconnect is a list of one tuple, so you need to give disconnect the index of that tuple. In this case: [0] try: code:
Proteus Jones fucked around with this message at 23:23 on Sep 8, 2015 |
# ¿ Sep 8, 2015 22:50 |
|
Gothmog1065 posted:STUFF I thought I was going cross-eyed, but I think I found your error. First off I was wrong. The remove is definitely: Python code:
Here's the working if, elif, else: Python code:
|
# ¿ Sep 9, 2015 04:28 |
|
How do I get 3.5.0 in anaconda. I mean I see it there, taunting me, when I do a 'conda search python', but 3.4.3 is the "latest" version when I do a 'conda update python'. I've just started using anaconda, and I'm still fumbling around in it.
|
# ¿ Sep 14, 2015 00:14 |
|
Dominoes posted:Wait. Fair enough. I just wish it wouldn't list it as a result in the conda search like it could actually be installed.
|
# ¿ Sep 14, 2015 00:26 |
|
Dominoes posted:http://continuum.io/blog/python35 Kick rear end, thanks. I think setting up an environment is the better way to go anyway, until I'm sure I want 3.5 as the default.
|
# ¿ Sep 14, 2015 21:35 |
|
Emacs Headroom posted:As my analysis / modeling evolves, I end up moving code from inside the notebook to a library in Python that gets imported into the notebook (and re-used by other notebooks). The library is the time to add unit tests, write good docstrings, etc. I don't use notebooks (really I do different stuff with my programs), but I've found creating libraries has been very useful to me, since there have been some classes I've used over and over again in different projects. I've found that while it adds a little more time to planning and a bit more effort programming and documenting when creating it for the first time, it's saved me oh so much time as opposed to cutting and pasting code and hammering it to fit. **kwargs are my bestest friends.
|
# ¿ Sep 24, 2015 16:31 |
|
OK, I'm running into an issue I'm just not getting. pexpect is dumping out on me because of a weird error regarding the timeout value. It dumps out every time at 'i = device.expect(self.password_prompt, self.en_prompt)' with the following error:code:
Python code:
Python code:
|
# ¿ Sep 26, 2015 21:43 |
|
Munkeymon posted:QJ was arguing against sharing code at all, not about how it's shared and that bugs me purely from a consumer of scientific output standpoint because it's a great way to accidentally hide errors that affect results. But that's *not* what he's saying? Unless I completely missed something elsewhere, he even mentioned having the code available for review to make sure the methodologies are appropriate and correct. He's just saying he doesn't see the point of a Notebook at all and it's sloppier than using a formally coded program.
|
# ¿ Sep 28, 2015 15:52 |
|
QuarkJets posted:Sounds pretty straightforward to me. Check out docx2txt for dumping the raw text to an ascii format. From there it's all a matter of intelligently extracting the pieces that you want, but it sounds like you have some good ideas of how to do this. Once you've identified what everything is, dumping it to a CSV is extremely easy re: CSV. There the builtin 'csv'. I use it all the time and it's very easy to use. Or there's always the option to write it out as a standard file just separating the elements with a ',' and manually adding a '\r\n' at the end of each row. But that seems like a lot of work compared to just using csv.
|
# ¿ Oct 3, 2015 08:10 |
|
Superdawg posted:Makes sense. Thanks for the help. I've always used this to prune items from my list: Python code:
|
# ¿ Oct 4, 2015 21:32 |
|
Microsoft OneDrive dev team just released this today: https://github.com/OneDrive/onedrive-sdk-python
|
# ¿ Oct 9, 2015 03:24 |
|
spiralbrain posted:This helps. Thank you. I want the virtualenv to be used for Python 3.X (forget which version is loaded on my other laptop) so yeah, currently its not pointed at that and I could see it was giving me a path error for the Flask import when I tried running the basic Flask hello world app so I figured something in the virtualenv wasn't setup correctly. Thanks for that command. You may want to look into Anaconda Python. I really like conda for creating environments. code:
Another nice thing is I can point PyCharm to the environment directory, and it will take it from there automatically using the conda environment on a project by project basis.
|
# ¿ Oct 15, 2015 04:05 |
|
Cingulate posted:Is there a painless way of moving my primary (3.4) anaconda environment to 3.5? I have a huge bunch of conda packages installed, some from binstar. won't conda update --all do it? EDIT: No it won't. Sorry I thought they had released 3.5 and that's what you were asking. Proteus Jones fucked around with this message at 02:06 on Oct 26, 2015 |
# ¿ Oct 26, 2015 02:04 |
|
https://www.continuum.io/blog/company-blog/anaconda-24-release PyCharm 5 was released this week as well. It's like Christmas
|
# ¿ Nov 4, 2015 16:31 |
|
QuarkJets posted:I personally can't do it, because _ looks awful to me, but it's fine if others want to do that. Same. And it always throws me for a second when I see it others' code.
|
# ¿ Apr 11, 2016 13:13 |
|
Loving Africa Chaps posted:Just doing tabs but for some reason the code tags make it look weird Don't SQL queries end with a ';' ? It's been years since I've interacted with a database using SQL. Most of my python scripts just use flat files for input and results.
|
# ¿ May 5, 2016 18:41 |
|
The Gasmask posted:Sorry, I didn't phrase it the best, but I figured it out. That part you quoted was incorrect of course, it's a variable regardless, but I just wasn't sure if I could reuse those shortened variable names for different blocks of code. Technically yes. But in practice, it's not recommended.
|
# ¿ Aug 12, 2016 17:10 |
|
I'm in a weird situation where I'm developing a python script on one machine in a conda environment, but I need to run it on a Windows box. Normally, not a big deal since I have Anaconda installed and up to date on both. However, this script relies on pexpect, which has some unix lib dependancies. So I'm limited to a Cygwin instance here. I tried to install the linux Anaconda, but it dumps out when it's trying to install conda. So my question is this: pexpect is currently the only thing other std libs that I'm using for this and it's already installed in Cygwin via pip.. Python3 on Cygwin is 3.4.3. So far, I've only specified my conda envs with "python3". Can I specify a specific point release of python for my env? If not, what should I look out for in my source to make sure it will execute in the Cygwin environment?
|
# ¿ Sep 19, 2016 18:09 |
|
BigRedDot posted:Yes, you can specify python versions like any other conda package: Thanks!
|
# ¿ Sep 19, 2016 21:39 |
|
Martytoof posted:Man there are like 900 ways to install Py3 on OSX. I'm just going to brew install python3 and forget about it before I start to obsess about which is the best down the road. Never going to actually learn if I keep nitpicking my infrastructure :| Anaconda will never let you down.
|
# ¿ Sep 21, 2016 12:59 |
|
accipter posted:What are peoples thoughts on unicode variable names (e.g., Φ)? I do a lot of programming of equations that might have variables without physical meaning (no proper name) and are just a greek symbol. I will usually use an ascii representation of that variable because it is simpler to enter, but it is a little removed from the original reference. If you're working in Python3 you should be fine, since source file encoding is UTF-8. If you're using 2.x, I think you need to declare the encoding like this (not 100%, I had to look it up) Python code:
Proteus Jones fucked around with this message at 18:52 on Feb 1, 2017 |
# ¿ Feb 1, 2017 18:50 |
|
Eela6 posted:As of yesterday, Anaconda released version 4.3 - which has Python 3.6 as a default! Now is a great time to start using Python 3.6. Yay!
|
# ¿ Feb 2, 2017 04:59 |
|
|
# ¿ Apr 27, 2024 08:48 |
|
baka kaba posted:I've been using Visual Studio Code a bunch for things lately, might be worth putting that in the IDEs section since it's the hotness and people might already be using it? They have a Python page and that Code Runner extension is real nice too It's nice and I use it for quick and dirty edits when I don't want to load PyCharm, or I'm on a computer I don't have access to PyCharm. I would probably not call it an IDE (especially for macOS). It's really more of a language aware editor.
|
# ¿ Mar 6, 2017 13:30 |