|
The Royal Scrub posted:Is there a way to set variable type once and be done? Designating a variable as int(input(variable),10) every time I redefine it doesn't seem right. Python uses type inference, so you aren't declaring a variable to be a specific type. What you're doing is using the int() built-in function to parse the result of the input() function(which is a string, because that's what the function returns) into an int. int() returns an int, so the variable is assigned an int, that's all. This is conceptually like using C's atoi(), and ultimately, any time you get information from standard input, you must do something like this. I believe that this is the case irrespective of the language you're using; as you can see, even C must do the same thing(though it provides a facility to make this case more convenient in the form of scanf()). Fergus Mac Roich fucked around with this message at 05:00 on Dec 16, 2015 |
# ? Dec 16, 2015 04:56 |
|
|
# ? May 9, 2024 02:43 |
|
The Royal Scrub posted:Is there a way to set variable type once and be done? Designating a variable as int(input(variable),10) every time I redefine it doesn't seem right. Names are ambiguous references to any kind of Python object. input() returns a string. Even in a statically typed language: code:
Python code:
e: base isn't length salisbury shake fucked around with this message at 05:15 on Dec 16, 2015 |
# ? Dec 16, 2015 05:02 |
|
That's going to fail silently if something goes wrong. I would just doPython code:
|
# ? Dec 16, 2015 05:22 |
|
The Royal Scrub posted:Is there a way to set variable type once and be done? Designating a variable as int(input(variable),10) every time I redefine it doesn't seem right. No. Make a function that does that: Python code:
|
# ? Dec 16, 2015 18:02 |
|
Is there a way to make Pycharm stop weak-warning uppercase variable names? Unlike some inspections, the only alt-enter option is to rename the variable. I can't find a suitable error code to ignore on this page. I can disable the pep8 naming convention inspection, but that's broader than I'd like.
Dominoes fucked around with this message at 13:12 on Dec 26, 2015 |
# ? Dec 26, 2015 13:01 |
|
Hey quick ipdb question: is there a way to load from a python file while in the debugger? In my case I've ipdb.set_trace()'d into my app, but now I want to load some utilty functions into the namespace. If I was in the interpreter I would just use %run or %load. What's the best way to do this?
|
# ? Dec 29, 2015 16:46 |
|
Feral Integral posted:Hey quick ipdb question: is there a way to load from a python file while in the debugger? In my case I've ipdb.set_trace()'d into my app, but now I want to load some utilty functions into the namespace. If I was in the interpreter I would just use %run or %load. What's the best way to do this? I've never really investigated this, I just do something like: Python code:
|
# ? Dec 29, 2015 23:21 |
|
Thermopyle posted:I've never really investigated this, I just do something like: Oh, that seems...obvious. Haha thanks!
|
# ? Dec 30, 2015 02:02 |
|
Dominoes posted:Is there a way to make Pycharm stop weak-warning uppercase variable names? Unlike some inspections, the only alt-enter option is to rename the variable. I can't find a suitable error code to ignore on this page. I can disable the pep8 naming convention inspection, but that's broader than I'd like. The easiest way, of course, is to use PEP8 compliant variable names.
|
# ? Dec 30, 2015 23:47 |
|
KernelSlanders posted:The easiest way, of course, is to use PEP8 compliant variable names. Sometimes pep8 is annoying.
|
# ? Dec 30, 2015 23:54 |
|
Nippashish posted:Sometimes pep8 is annoying. Agreed, but I find its usually better to just put up with it.
|
# ? Dec 30, 2015 23:56 |
|
KernelSlanders posted:The easiest way, of course, is to use PEP8 compliant variable names. Nippashish posted:Sometimes pep8 is annoying.
|
# ? Dec 31, 2015 01:21 |
|
I would say to just disable all PEP8 naming conventions, although you might be able to define your own set of warning rules that include most of the naming conventions but not the ones that you don't want. Kind of a pain in the rear end and probably more trouble than it's worth.
|
# ? Dec 31, 2015 03:22 |
|
Dominoes posted:Scientific programming makes sense with uppercase variable names (including things like Δ) when convention calls for them. Popular libraries like scikit learn use them in documentation. I'm not sure that arguing you want unicode variable names is much of an improvement. I don't follow your point about sklearn. Are you saying that there is code in an sklearn docstring that doesn't follow sklearn coding standards?
|
# ? Dec 31, 2015 05:52 |
|
QuarkJets posted:I would say to just disable all PEP8 naming conventions. KernelSlanders posted:I'm not sure that arguing you want unicode variable names is much of an improvement.
|
# ? Dec 31, 2015 11:08 |
|
idk writing simply dt is a super old convention in scientific programming, graphics programming, maybe even programming in general I'd say
|
# ? Dec 31, 2015 11:16 |
|
Symbolic Butt posted:idk writing simply dt is a super old convention in scientific programming, graphics programming, maybe even programming in general I'd say Yeah, changing to δt kind of misses the point. What's wrong with dt or deltaT?
|
# ? Dec 31, 2015 16:31 |
|
KernelSlanders posted:Yeah, changing to δt kind of misses the point. What's wrong with dt or deltaT? Dominoes fucked around with this message at 16:40 on Dec 31, 2015 |
# ? Dec 31, 2015 16:36 |
|
Er... delta_t I mean.
|
# ? Dec 31, 2015 17:39 |
|
KernelSlanders posted:Yeah, changing to δt kind of misses the point.
|
# ? Jan 1, 2016 20:51 |
|
Cingulate posted:That's one of the selling points of Julia. Being able to use unicode characters in variable names sounds like a complete nightmare to me
|
# ? Jan 1, 2016 23:04 |
|
You're probably looking at this from a software engineer standpoint. Julia, I think, is aimed at scientists-first who want to have their code look as much as math formulae as possible.
|
# ? Jan 1, 2016 23:11 |
|
Should be simple iterating through dictionaries question.Haven't worked with them until today. I'm reading from a file. It reads a part of a line that denotes how many years a player has been playing. It works fine. code:
Values of YTot are another number that is added up. I need to put the value of YTot['2'] / Y['2'] into YAvg ['2'] in a loop. code:
ButtWolf fucked around with this message at 23:31 on Jan 1, 2016 |
# ? Jan 1, 2016 23:29 |
|
You need to reference by the key, not value.Python code:
Dominoes fucked around with this message at 23:51 on Jan 1, 2016 |
# ? Jan 1, 2016 23:43 |
|
Dominoes posted:You need to reference by the key, not value. Why did you rename anything? Now there is y_avg - y - y_tot - count_tot ... I don't understand. BTW: most of the data is not zeroes, but I'll set up an if !0 thingy.
|
# ? Jan 1, 2016 23:47 |
|
The python style guide recommends using only lowercase letters in variable names, and using underscores to separate words. I'm not clear how you're constructing the dicts, but I think the prob is you're accessing by values instead of keys. Dominoes fucked around with this message at 00:00 on Jan 2, 2016 |
# ? Jan 1, 2016 23:50 |
|
ButtWolf posted:I need to put the value of YTot['2'] / Y['2'] into YAvg ['2'] code:
|
# ? Jan 2, 2016 00:09 |
|
Cingulate posted:How about Dominoes posted:The python style guide recommends using only lowercase letters in variable names, and using underscores to separate words. I don't care 'bout no naming conventions right now. This program is all bullshit for me anyway. Although thanks for the link, I'll read it eventually. Now I need to learn how to format when printing dictionaries to files. Uggh... Anyone here have any experience webscraping?
|
# ? Jan 2, 2016 05:33 |
|
ButtWolf posted:
Also start paying attention to naming conventions, they're there for a reason.
|
# ? Jan 2, 2016 15:32 |
|
Cingulate posted:You're probably looking at this from a software engineer standpoint. Julia, I think, is aimed at scientists-first who want to have their code look as much as math formulae as possible. I am a scientist, by training and by profession, and this sounds like a terrible idea to me. I can't feel sorry enough for the first grad student who has to receive and modify legacy code with a bunch of unicode characters littered throughout it. I would also wager that most scientists don't actually care about spending the extra time looking up unicode characters in order to have their code look like math formulae; I think that we mostly just want to code in a way that's easy and that executes quickly. Unless maybe LaTeX syntax for creating unicode characters is supported, I suppose
|
# ? Jan 2, 2016 21:18 |
|
QuarkJets posted:Unless maybe LaTeX syntax for creating unicode characters is supported, I suppose
|
# ? Jan 2, 2016 21:35 |
|
Dominoes posted:Julia, Jupyter, and IPython syntax: backslash, then the name like 'pi', then tab. That's LaTeX syntax and not what I was imagining, that's pretty cool then
|
# ? Jan 2, 2016 21:42 |
|
Cingulate posted:That's one of the selling points of Julia. Python also allows a lot of characters outside of ASCII to be used in identifier names (but not all of them; they typically have to have the categorization "letter" in the Unicode database). (No code tags because vBulletin mangles non-ASCII characters inside those) quote:from pprint import pprint code:
|
# ? Jan 3, 2016 16:09 |
|
edit: Got it. Anyone willing to help me tomorrow? I'm on the last part of my project and kind of burnt out. I have a program that reads a .csv and does some calculations based on the info. I how have a text that I need to do the same thing with only it's formatted differently, and I'm having trouble. email - sisyphean.0 at gmail Shouldn't be too intensive, I'm just dumb. ButtWolf fucked around with this message at 06:17 on Jan 4, 2016 |
# ? Jan 4, 2016 03:31 |
|
Lysidas posted:Python also allows a lot of characters outside of ASCII to be used in identifier names (but not all of them; they typically have to have the categorization "letter" in the Unicode database). I just checked and nabla doesn't work because it's not a letter
|
# ? Jan 4, 2016 12:27 |
|
Hey new Bokeh time. https://goo.gl/rn9Dca Images link to http://demo.bokehplots.com
|
# ? Jan 7, 2016 01:52 |
|
If anyone has experience with beautifulsoup, I could use a little help. I use a program to pull in some data code:
code:
I can just look at the file and manually add it, but I have a thousand or so lines to add, so I don't want to.
|
# ? Jan 8, 2016 03:06 |
|
Can't you just use an if statement? Quick and dirty, something like:Python code:
|
# ? Jan 8, 2016 03:11 |
|
SurgicalOntologist posted:Can't you just use an if statement? Quick and dirty, something like: Navigable string has no attribute 'text'
|
# ? Jan 8, 2016 04:15 |
|
|
# ? May 9, 2024 02:43 |
|
Right I've encountered that problem before. Better to do a second find then iterate over all the children. I don't know enough about HTML to know what those NavigableStrings are, but they get in the way. Something like this should filter them out.Python code:
I added the attrs thing in there too so you don't get that "C" which I assume is the heading. I'll also mention that pandas can read HTML into dataframes directory, so you might want to try that. http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_html.html Often something like Python code:
SurgicalOntologist fucked around with this message at 04:30 on Jan 8, 2016 |
# ? Jan 8, 2016 04:26 |