|
tef posted:It's worth pointing out that many of these algorithms operate on *fixed length arrays* not *python lists*. When you're calling pop, insert, append, you're changing the length of the list, as well as changing the list. With these old algorithms, you probably want to stick to arr[0] = ..... Thanks for the explanation. The reason behind i is that I'm planning on teaching CS in the UK and it's part of the school curriculum. They don't have to be able to code it, just have an idea of how it works and be able to trace it. The Python explanation sounds like a merge sort. I'll do some reading about it. I've not yet written the code for my merge sort. I'm not really sure how to code it to make a list for each element. I'm sure some Googling would give me an idea.
|
# ? Mar 18, 2018 22:24 |
|
|
# ? Jun 5, 2024 04:57 |
|
I'm trying to figure out how this torrent name parsing library works, and I'm stumped when looking at the code. I get the gist of it but I don't fully understand how it goes about it. https://github.com/divijbindlish/parse-torrent-name/blob/master/PTN/parse.py What's a good method of attack when trying to figure out something like this? Toss in print statements everywhere? Does PyCharm have functionality specifically for this that I should explore?
|
# ? Mar 19, 2018 02:33 |
|
I don’t use pycharm, but I would start here: https://www.jetbrains.com/help/pycharm/debugging.html
|
# ? Mar 19, 2018 03:22 |
|
Assuming PyCharm has the same basic debugging capabilities as IntelliJ, you can add breakpoints wherever, then right-click them and uncheck pause execution (or whatever), and add your own print statement in the "execute this" bit - you can include variables and all that. It's like adding print statements without sticking them in the code But stepping through and watching what happens is your best bet
|
# ? Mar 19, 2018 04:19 |
|
baka kaba posted:Assuming PyCharm has the same basic debugging capabilities as IntelliJ, you can add breakpoints wherever, then right-click them and uncheck pause execution (or whatever), and add your own print statement in the "execute this" bit - you can include variables and all that. It's like adding print statements without sticking them in the code It has all that. My absolute favorite thing is the just being able to display variable contents at various break points. It’s been invaluable in helping me zero in on logical errors I’ve made.
|
# ? Mar 19, 2018 06:35 |
|
My fav thing is being able to reach in and change the value of variables (even by executing some arbitrary code) and then set it running again
|
# ? Mar 19, 2018 06:44 |
|
Hughmoris posted:I'm trying to figure out how this torrent name parsing library works, and I'm stumped when looking at the code. I get the gist of it but I don't fully understand how it goes about it. PDB or IPython's debugger (ipdb) would work well too, and you don't need to learn a full IDE: https://www.safaribooksonline.com/blog/2014/11/18/intro-python-debugger/
|
# ? Mar 19, 2018 06:45 |
|
Conditional breakpoints in PyCharm are good things too. (right-click the breakpoint in the gutter) (randomly googled image. Being a sane human being I use a dark theme)
|
# ? Mar 19, 2018 17:51 |
|
... there is a non-dark theme in pycharm?
|
# ? Mar 19, 2018 18:52 |
|
Cingulate posted:... there is a non-dark theme in pycharm? The default one is non-dark and is the one I use because the dark themes all blow.
|
# ? Mar 19, 2018 22:03 |
|
Stop saying wrong things! (I used Darkula and monokai for a long time, but a few months ago I switched to the Material UI theme/plugin)
|
# ? Mar 19, 2018 22:05 |
|
I believe you can set up PyCharm to pause on any exception, or even just unhandled ones, right? I know in Visual Studio and Visual Code you can. Not sure about Spyder though.
|
# ? Mar 19, 2018 23:58 |
|
Yeah you can - Ctrl-Shift-F8 to bring up the options.
|
# ? Mar 20, 2018 03:49 |
|
Is there a read the docs style theme for jupyter notebooks? The regular theme is kinda plain and I really like the rtd theme.
|
# ? Mar 20, 2018 08:16 |
|
Sad Panda posted:I was learning some Comp Sci and that involved learning about linear search, binary search, bubble sort, insertion sort and merge sort. I decided that the best way to make sure that I understand them was to code them. Yeah, there's some extra printing, and printing the whole list makes it N^3 instead of N^2. I'm not sure why you're doing so much extraneous stuff though. In python, bubble sort is just: Python code:
|
# ? Mar 23, 2018 00:53 |
|
I'm getting ready to write, at least two microservices for deploying and maintaining state of an app, probably another 3-5 microservices related to deploying other apps. These will just be serving up json from a standard restful api using basic auth deep inside the protected network and not accessible outside the company. No UI or twitter for zombies, etc. I'm fairly happy with using Flask at this point. It seems like Flask is the go-to library for microservices? I am looking at using PeeWee as my ORM and then connecting to a postgres db. Is this a pretty good solution? Peewee seems actively developed despite having a fairly small user base. The big plus for me is that it's especially straightforward. Other options include Flask/SQLAlchemy, SQLAlchemy being more difficult to use and a lot meatier. Option C is something in the Django-world. Django has a fair bit of rails-magic to it, and I'm trying to imagine a future where my ops buddies can debug the code without having to call me when I'm on vacation in the bahamas someday. Am I going to bet happy with Python/Flask/Peewee? My predecessor used Cherry Py for something similar at another company.
|
# ? Mar 26, 2018 09:06 |
|
Hadlock posted:I'm getting ready to write, at least two microservices for deploying and maintaining state of an app, probably another 3-5 microservices related to deploying other apps. These will just be serving up json from a standard restful api using basic auth deep inside the protected network and not accessible outside the company. No UI or twitter for zombies, etc. I'm in the process of doing something similar, and I've pretty much also decided Flask is the way to go. I think Django REST Framework looks pretty nice if you need the features it provides like a built-in ORM, more robust user authentication methods, web browsable API, throttling, plenty of other stuff I care even less about. I don't really need any of that though and it doesn't sound like you do either, and Flask is nice since it's a lot easier to integrate whatever ORM you're comfortable with and is just lighter. I think DRF'd be great if I were more familiar with django already, or the API were public facing at all.
|
# ? Mar 26, 2018 17:37 |
|
I just posted this in the web dev thread:Thermopyle posted:A good resource for learning Python is the Python thread. We're all very helpful over there . Personally, I would always use Django because it's easy to use it in as lightweight a manner as Flask, but its easier to add more features if you need them. That is not to say anything bad about Flask...it's a great project.
|
# ? Mar 26, 2018 18:19 |
|
Same; Django had a steep learning curve, but for me, at least, it's easier to set up a Django project than try to make Flask plugins play well together. Most of the projects I've worked on involve making a website or REST api, so this may not be applicable to other uses.
|
# ? Mar 26, 2018 18:27 |
|
Dominoes posted:Same; Django had a steep learning curve, but for me, at least, it's easier to set up a Django project than try to make Flask plugins play well together. Most of the projects I've worked on involve making a website or REST api, so this may not be applicable to other uses. FWIW, Django probably had a steep learning curve to you because you were also (implicitly) learning how web application servers worked. You would likely now have a much easier time learning some other web app server even if it was, by some objective standard, "harder" to learn than Django just because you understand the space now. (assuming by "steep learning curve" you colloquially mean "hard to learn" rather than its technical meaning of "quick to learn") Thermopyle fucked around with this message at 20:15 on Mar 26, 2018 |
# ? Mar 26, 2018 19:15 |
|
Django really isn't that hard, I've never totally understood people saying that it is. It has some up-front default config that you have to figure out but the documentation is pretty solid and none of the concepts in Django are novel.
|
# ? Mar 26, 2018 19:16 |
|
Thermopyle posted:FWIW, Django probably had a steep learning curve to you because you were also (implicitly) learning how web application servers worked. The March Hare posted:Django really isn't that hard, I've never totally understood people saying that it is. It has some up-front default config that you have to figure out but the documentation is pretty solid and none of the concepts in Django are novel. There's a lot of specific syntax to memorize, but most of it's provided by the tutorial. Dominoes fucked around with this message at 19:43 on Mar 26, 2018 |
# ? Mar 26, 2018 19:35 |
|
Now that I think about it, I can see being new and being totally confused by CBVs/generic CBVs/function views. I think models are fairly reasonable (especially now that you don't need an outside library for migrations), functional views are totally intuitive in their machinations, urls aren't that bad as long as you read the docs, and forms are terrible even if you do read the documentation.
|
# ? Mar 26, 2018 20:10 |
The March Hare posted:Now that I think about it, I can see being new and being totally confused by CBVs/generic CBVs/function views. I think models are fairly reasonable (especially now that you don't need an outside library for migrations), functional views are totally intuitive in their machinations, urls aren't that bad as long as you read the docs, and forms are terrible even if you do read the documentation. The docs seem to be downplaying function-based views as much as they can; if they aren't planning to deprecate them outright I feel like they're going to turn into a semi-supported feature that just confuses everyone down the line.
|
|
# ? Mar 26, 2018 20:16 |
|
The March Hare posted:I think models are fairly reasonable (especially now that you don't need an outside library for migrations)
|
# ? Mar 26, 2018 21:02 |
|
Anyone have any recommendations for resources for learning MicroPython (with the ESP2866)? I see a few books on Amazon but none look promising and I can't really find good Youtube videos or other courses online.
|
# ? Mar 26, 2018 21:10 |
|
Data Graham posted:The docs seem to be downplaying function-based views as much as they can; if they aren't planning to deprecate them outright I feel like they're going to turn into a semi-supported feature that just confuses everyone down the line. Django FBV's won't be depracated, because all Django views are function based views...even the so-called class-based views which are decomposed to a regular function by Django. That's what the as_view method on CBVs does. This is because a Django view is, by definition, a callable that takes an HttpRequest and returns an HttpResponse.
|
# ? Mar 26, 2018 22:28 |
|
vikingstrike posted:If you need to create a DataFrame, and pyspark has a DataFrame creator function that gives you the desired output, I'm not sure why you'd try to roll your own. Turning CSVs into DataFrames is some of the most basic functionality of a library like this. So this was a ways back, but I realized why I had such a convoluted way of importing CSV's...apparently pandas dataframes and Spark dataframes are different things and have to be handled differently. Spark has similar things to pandas, but working with CSV's seems to be more of a hassle .
|
# ? Mar 27, 2018 00:38 |
|
Crossposting from the AWS thread but I'm a Python noob and I'm trying to parse some JSON data inside a notification event. Has anyone used Lambda to parse SNS event? I've been trying to parse an AWSConfig rule's SNS events and using the data to do various things. I'm able to parse the data up to a point, but I can't seem to get the message JSON data that I want. I'm using python 2.7, and json, boto3 imports. I think my issue is the JSON is being read as a single key. Anyone know how to do this? code:
output: code:
SnatchRabbit fucked around with this message at 23:29 on Mar 29, 2018 |
# ? Mar 29, 2018 23:18 |
|
SnatchRabbit posted:Crossposting from the AWS thread but I'm a Python noob and I'm trying to parse some JSON data inside a notification event. What are you hoping for the end result to be? message = json.loads(message) returns a dict, and printing it will display the whole thing as a string.
|
# ? Mar 30, 2018 00:29 |
|
Tigren posted:What are you hoping for the end result to be? message = json.loads(message) returns a dict, and printing it will display the whole thing as a string. I want the message to be the json portion of the event that starts with message so i can grab individual values out of it.
|
# ? Mar 30, 2018 00:44 |
|
That's what json.loads has done. Printing it just displays message (which is now a python dict) as string so it can be displayed.
Dr Subterfuge fucked around with this message at 00:53 on Mar 30, 2018 |
# ? Mar 30, 2018 00:51 |
|
Dr Subterfuge posted:That's what json.loads has done. Printing it just displays message (which is now a python dict) as string so it can be displayed. Right, but what I need is message to be this portion, in JSON, so I can use individual values (strings) like resourceID, and put that in a statement later. Not sure that makes sense, like I said I'm terrible with python. code:
|
# ? Mar 30, 2018 01:01 |
Unless I'm misunderstanding you, you already have everything you need. message is currently a dict with all the values that were loaded in from the JSON. So you can access resourceID like message['resourceID']
|
|
# ? Mar 30, 2018 02:29 |
|
I'm working on a "coding test" for a job application but unless I'm missing something I don't think they've given me enough to work with. Here's the instructions from the email:quote:Problem description: Then there's a link to five images and this is the API "documentation": quote:PhotoAI API I mean, I think some of this stuff can be executed via curl/requests but don't they need to provide some details on how to interact with their API? Just speaking of Amazon, they have buttloads of documentation on how to use boto to work with S3, EC2, IAM security and all that stuff. The API seems to be a specialized image-recognition app so I don't think generic REST commands will do it. Am I missing something or do I really need to send them a reply asking for more info?
|
# ? Mar 30, 2018 02:47 |
|
SnatchRabbit posted:Right, but what I need is message to be this portion, in JSON, so I can use individual values (strings) like resourceID, and put that in a statement later. Not sure that makes sense, like I said I'm terrible with python. Like Data Graham said getting resourceID from message would just be message['resourceID']. If you need to turn it back into a JSON string you would do json.dumps(message)
|
# ? Mar 30, 2018 04:09 |
|
SnatchRabbit posted:Right, but what I need is message to be this portion, in JSON, so I can use individual values (strings) like resourceID, and put that in a statement later. Not sure that makes sense, like I said I'm terrible with python. As mentioned in the prior replies there isn't anything obviously wrong with your Python, but the example response you provided isn't consistent with the dict you pasted. For example, the JSON has a configRuleName key with a string value, and the dict has a configRuleNames key with a list of strings value (it only has one string). The structure of JSON example you gave is clearly not entirely the same as the structure of whatever JSON you are passing to json.loads. I don't know much about AWS, but determining the cause of that discrepancy is where I would start.
|
# ? Mar 30, 2018 08:38 |
|
Data Graham posted:Unless I'm misunderstanding you, you already have everything you need. message is currently a dict with all the values that were loaded in from the JSON. So you can access resourceID like Yup, this worked like a charm. Thanks, everyone!
|
# ? Mar 30, 2018 16:10 |
|
Seventh Arrow posted:I'm working on a "coding test" for a job application but unless I'm missing something I don't think they've given me enough to work with. Here's the instructions from the email: Ok, so it looks like there was more to the pdf than I initially thought. Woops! I've run into a snag, though...they want the images submitted to the API using the format in this example: quote:1. SUBMIT REQUESTS So I tried to come up with my own code: code:
Does it maybe have to do with the way that the string is formatted?
|
# ? Mar 30, 2018 20:59 |
|
|
# ? Jun 5, 2024 04:57 |
|
You have a typo in image 2.
|
# ? Mar 30, 2018 21:05 |