title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
Pyvmomi get folders name
39,706,470
<p>I'm new to Python and Django and I need to list all my VMs. I used pyvmomi and Django but I can't get the folders name from VSphere, it shows a strange line.</p> <blockquote> <p>VMware list</p> <p>'vim.Folder:group-v207'</p> <p>'vim.Folder:group-v3177'</p> <p>'vim.Folder:group-v188'</p> </blockquot...
0
2016-09-26T15:14:27Z
39,752,543
<p>You need to specifically state you want the name, like this:</p> <pre><code>vmFolders = datacenter.vmFolder.childEntity for folder in vmFolders: print(folder.name) </code></pre>
0
2016-09-28T16:05:19Z
[ "python", "django", "vsphere", "pyvmomi" ]
Error type in my work about python
39,706,493
<pre><code>#!/usr/bin/env python # coding=utf8 value=input("please enter value:") result=hex(value) r=hex(0xffff-result) print r print result TypeError: unsupported operand type(s) for -: 'int' and 'str' </code></pre> <p>I study python for a few days,I try this python job,I can't understand what's the shap...
-4
2016-09-26T15:15:41Z
39,706,611
<p><code>hex</code> returns a string containing the hexadecimal representation of the given <code>value</code>. You don't need to convert the value to hex, though, since <code>0xffff</code> is just an <code>int</code> literal.</p> <p>Don't use <code>input</code> in Python 2; use <code>raw_input</code> to get a string,...
0
2016-09-26T15:21:01Z
[ "python" ]
Error type in my work about python
39,706,493
<pre><code>#!/usr/bin/env python # coding=utf8 value=input("please enter value:") result=hex(value) r=hex(0xffff-result) print r print result TypeError: unsupported operand type(s) for -: 'int' and 'str' </code></pre> <p>I study python for a few days,I try this python job,I can't understand what's the shap...
-4
2016-09-26T15:15:41Z
39,706,919
<p>When you are just beginning with Python you can get a huge amount of help by just running an interactive Python session and typing code in. Just enter the command</p> <pre><code>python </code></pre> <p>The code you enter can be expressions or statements. Expressions are automatically evaluated, and the result prin...
0
2016-09-26T15:36:02Z
[ "python" ]
Terminating a program within a time frame through python
39,706,661
<p>I'm running a fortran code from a python script which sometimes takes a while to run. Thus I'm limiting the run time with a code taken from <a href="http://stackoverflow.com/a/13821695/3910261">this link</a>:</p> <pre><code>def timeout(func, args=(), kwargs={}, timeout_duration=15, default=1): import signal ...
1
2016-09-26T15:24:02Z
39,706,841
<p>There's a timeout argument on check_output, just set it to 15 seconds.</p> <pre><code>try: subprocess.check_output(['arg1', 'arg2'], timeout=15) except: print("Timed out") </code></pre> <p>Documentation here <a href="https://docs.python.org/3/library/subprocess.html#subprocess.check_output" rel="nofollow">http...
0
2016-09-26T15:32:29Z
[ "python", "subprocess", "popen" ]
Terminating a program within a time frame through python
39,706,661
<p>I'm running a fortran code from a python script which sometimes takes a while to run. Thus I'm limiting the run time with a code taken from <a href="http://stackoverflow.com/a/13821695/3910261">this link</a>:</p> <pre><code>def timeout(func, args=(), kwargs={}, timeout_duration=15, default=1): import signal ...
1
2016-09-26T15:24:02Z
39,707,979
<p>Not the most sophisticated piece of code in the world but it may be useful.</p> <pre><code>import subprocess, time x = subprocess.Popen(['sleep', '15']) polling = None i = 0 while polling == None: time.sleep(1) polling = x.poll() i +=1 if i &gt; 15: break if polling == None: try: x.kill(...
1
2016-09-26T16:34:26Z
[ "python", "subprocess", "popen" ]
Google analytics duration zero for the pages visited by Selenium
39,706,711
<p>I want to visit a web site with Selenium and python like this:</p> <pre><code>browser = webdriver.Firefox() browser.get(url) time.sleep(20) browser.close() </code></pre> <p>When I check the duration in google analytic after an hour, I see the duratioin is zero. I've change it to this code to click on a link in the...
-1
2016-09-26T15:26:38Z
39,709,708
<p>Session duration is the delta between the timestamps of the first and the last interaction within a session (i.e. interactions with the same client id within a given timeframe). As far as I can tell your code will only create a single interaction per session, so there is no second data point to calculate a duration....
0
2016-09-26T18:18:40Z
[ "python", "selenium", "selenium-webdriver", "google-analytics" ]
Running sequential code in hdfs
39,706,713
<p>I am currently learning the "ins and outs" of working with Hadoop. Here's the </p> <p>current setup: I have sequential code that I use to create .txt files which I will use as the input data for my mappers. I have currently been running this sequential code "preprocess.py" on a local machine and then moving the gen...
0
2016-09-26T15:26:40Z
39,710,574
<p>It is possible. Just make sure that you push all generated files to single unix location in your python code. Once they are there you can use <code>subprocess</code> module to run to shift the generated file to HDFS. In code it have to wait until file is transferred. Also for making sure that you are not again copyi...
0
2016-09-26T19:11:49Z
[ "python", "hadoop" ]
Convert CURL Post to Python Requests Failing
39,706,735
<p>I am unable to successfully convert and execute a curl post command to python code.</p> <p>curl command</p> <pre><code>curl -X POST -H "Content-Type:application/json; charset=UTF-8" -d '{"name":joe, "type":22, "summary":"Test"}' http://url </code></pre> <p>Converted code</p> <pre><code>import requests import jso...
2
2016-09-26T15:27:43Z
39,707,404
<p>If you are using one of the latest versions of requests: Try using the 'json' kwarg (no need to convert to json explicitly) instead of the 'data' kwarg:</p> <pre><code>response = requests.post(url, json=data, headers=headers) </code></pre> <p>Note: Also, this way you can omit the 'Content-type' header.</p>
-1
2016-09-26T16:01:18Z
[ "python", "curl", "server", "python-requests" ]
Using win32com to MERGE and UNMERGE cells
39,706,776
<p>All,</p> <p>I have a <strong>table</strong> inside a <strong>Word document</strong> that contains <strong>merged cells</strong>. I would like to <strong>unmerge</strong> those cells using the <strong>win32com</strong> package.</p> <p>An example of this is when ROW 1 contains 5 cells, and ROW 2 contains 6 cells.</...
0
2016-09-26T15:29:44Z
39,732,201
<p>I found a solution to my problem. After a lot of searching it would appear that tables embedded inside of MS Word do NOT have a "merge" property associated with them. However, they do have a "width" property associated with them. Getting this using win32com looks something like this:</p> <pre><code>#See above fo...
0
2016-09-27T18:47:58Z
[ "python", "ms-word", "win32com" ]
Issues with Signal-Slot while using Qthread
39,706,786
<p>I wrote a sample code for my issue. This code should produce sum of two given numbers and show the result in text-browser then replace first number with sum, and add it to second number and show the result in text-browser again.This process should continues. The issues are:</p> <p>1 - Why signal is not working prop...
1
2016-09-26T15:30:00Z
39,774,529
<p>The example code won't work correctly because you are not keeping a reference to the <code>GeneralizedRun</code> window. So the first thing to fix is this:</p> <pre><code>class MainApplication(QMainWindow): ... def mainprogramrun(self): number1 = float(self.no1.text()) number2 = float(self...
1
2016-09-29T15:35:02Z
[ "python", "multithreading", "pyqt4", "signals-slots" ]
I wish to make sure items in a list don't have duplicate elements not present in inputted word
39,706,847
<p>Right, so I need to make sure that each item in a list when compared to an inputted word don't contain duplicate elements that are not present in the inputted word. It's a bit difficult to explain so I'll just show what I've got so far:</p> <pre><code>listword = input("Inputted word: ") listcomparison = ["su", "pic...
1
2016-09-26T15:32:39Z
39,707,529
<p>Use <a href="https://docs.python.org/3.5/library/collections.html#collections.Counter" rel="nofollow"><code>collections.Counter</code></a>.</p> <p>Here are some examples of the <code>collections.Counter</code> in action:</p> <pre><code>&gt;&gt;&gt; Counter("read") Counter({'a': 1, 'r': 1, 'e': 1, 'd': 1}) &gt;&gt;...
1
2016-09-26T16:08:33Z
[ "python", "list", "python-3.x", "for-loop", "while-loop" ]
Python - Make module method variables global good practice?
39,706,867
<p>I want to separate the code function of a script into a new module. I want to define some configs to pass as parameters in that module. Then, in the module I define this config as global. Is it a good practice? Is there a better solution?</p> <p><strong>main script:</strong></p> <pre><code>import myModule config ...
1
2016-09-26T15:33:30Z
39,706,935
<p>What I normally do when I need such kind of global variables is to make a class and define them there. So for example a Configuration class with values stored in them. </p> <p>This has the following advantages (not an ending list):</p> <ul> <li>The class constants/variables 'belong' to something which is more appl...
2
2016-09-26T15:37:05Z
[ "python", "python-2.7" ]
Serializing custom related field in DRF
39,706,882
<p>I am trying to make a serializer with a nested "many to many" relationship. The goal is to get a serialized JSON object contain an array of serialized related objects. The models look like this (names changed, structure preserved)</p> <pre> from django.contrib.auth.models import User PizzaTopping(models.Model): ...
0
2016-09-26T15:34:10Z
39,708,882
<p>Seems like there is an undocumented requirement. For write operations to work with a custom ManyToMany field, the custom field class <code>to_internal_value()</code> method needs to save the instance before returning it. The DRF docs omit this and the example of making a custom field (at <a href="http://www.django-r...
0
2016-09-26T17:26:42Z
[ "python", "json", "django", "serialization", "django-rest-framework" ]
django custom form clean() raising error from clean_field()
39,706,916
<p>I have created a custom form and need to override both of the <code>clean_field()</code> method and <code>clean()</code> method. Here is my code:</p> <pre><code>class MyForm(forms.Form): username=forms.RegexField(regex=r'^1[34578]\d{9}$') code = forms.RegexField(regex=r'^\d{4}$') def clean_username(sel...
0
2016-09-26T15:35:56Z
39,707,638
<p>In your <code>clean</code> method, you can check whether <code>username</code> is in the <code>cleaned_data</code> dictionary.</p> <pre><code>def clean(self): cleaned_data = super(MyForm, self).clean() if 'username' in cleaned_data: # username was valid, safe to continue ... else: ...
1
2016-09-26T16:14:46Z
[ "python", "django", "forms", "validation" ]
pandas error when convert object to datetime
39,706,970
<p>This is two lines of inputdataframe:</p> <pre><code> ts country os product_id total_users total_purchases 0 0000-00-00 Brazil iOS 1 0 1 0000-00-00 Germany 1 0 </code></pre> <p>I have tried following commands in...
0
2016-09-26T15:38:56Z
39,707,864
<p>easy peasy</p> <pre><code>df['ts'] = pd.to_datetime(df['ts'], errors ='coerce') </code></pre> <p>no need to clean the data. wrong timestamps will get the <code>NaT</code> (not a timestamp)</p>
1
2016-09-26T16:28:04Z
[ "python", "datetime", "pandas" ]
Pandas - Alternative to rank() function that gives unique ordinal ranks for a column
39,707,080
<p>At this moment I am writing a Python script that aggregates data from multiple Excel sheets. The module I choose to use is Pandas, because of its speed and ease of use with Excel files. The question is only related to the use of Pandas and me trying to create a additional column that contains <em>unique, integer-onl...
2
2016-09-26T15:44:53Z
39,708,191
<p>I think the way you were trying to use the <code>method=first</code> to rank them after sorting were causing problems. </p> <p>You could simply use the rank method with <code>first</code> arg on the grouped object itself giving you the desired unique ranks per group.</p> <pre><code>df['new_rank'] = df.groupby(['we...
1
2016-09-26T16:47:51Z
[ "python", "pandas", "ranking", "rank", "ordinal" ]
Reading binary file in c written in python
39,707,159
<p>I wrote numpy 2 dimensional float array as a binary file using </p> <p><code>narr.tofile(open(filename,"wb"),sep="",format='f')</code> </p> <p>and try to retrieve the same in c using</p> <pre><code>FILE* fin = fopen(filename,"rb") float* data = malloc(rows*2*sizeof(float)); fread(data, sizeof(float), rows*2, fin...
0
2016-09-26T15:49:08Z
39,707,478
<p>It may depends on system you are using, <code>ndarray.tofile()</code> outputs in little-endian, which means that the <strong>least significant byte is stored first</strong>, try to use <code>numpy.byteswap()</code> and then convert to file. Also try to do it without format specifier and see result. Documentation st...
0
2016-09-26T16:05:24Z
[ "python", "c", "arrays", "numpy" ]
Reading binary file in c written in python
39,707,159
<p>I wrote numpy 2 dimensional float array as a binary file using </p> <p><code>narr.tofile(open(filename,"wb"),sep="",format='f')</code> </p> <p>and try to retrieve the same in c using</p> <pre><code>FILE* fin = fopen(filename,"rb") float* data = malloc(rows*2*sizeof(float)); fread(data, sizeof(float), rows*2, fin...
0
2016-09-26T15:49:08Z
39,708,552
<p>Here is another way if you save your data in npy format through <code>np.save('foo.npy',narr)</code>. It is a (writer and) reader for 2D npy files that returns its data as a two dimensional Eigen matrix. Note that the code does lots of assumptions and only works for 2D arrays saved with the standard np save() option...
0
2016-09-26T17:08:24Z
[ "python", "c", "arrays", "numpy" ]
How to get an all sticky grid of Treeview and Scrollbar in Python Tkinter?
39,707,184
<p>What I want in Tkinter in Python 2.7 is the following grid layout:</p> <p><a href="http://i.stack.imgur.com/O1jHM.png" rel="nofollow"><img src="http://i.stack.imgur.com/O1jHM.png" alt="Grid Layout"></a></p> <p>However once, I start using the <code>grid()</code> functions instead of <code>pack()</code> functions, n...
0
2016-09-26T15:50:38Z
39,707,737
<p>You have several problems that are affecting your layout. </p> <p>First, some of the widgets inside <code>App</code> use <code>self</code> as the parent, some use <code>self.parent</code>. They should all use <code>self</code> in this particular case. So, the first thing to do is change the parent option of the <co...
1
2016-09-26T16:20:39Z
[ "python", "python-2.7", "tkinter", "treeview" ]
I want to print the json object in a tabular form passed using render_template() from python
39,707,192
<p>Python code is as follows:</p> <pre><code> @app.route("/send", methods=['GET', 'POST']) def send(): if request.method == "POST": findemail=request.form['email'] datafound=findlogic(findemail) data = jsonify(datafound) #return data return rend...
0
2016-09-26T15:50:48Z
39,711,982
<p>you cannot iterate a string like you want, but it looks like your <code>data</code> is a json string, so you could do something like:</p> <pre><code>json_data = json.loads(data) &lt;body&gt; {% for value in json_data['629513533'] %} &lt;li&gt;{{ x[value].xyz }} &lt;/li&gt; {% endfor %} &lt;/body&gt; <...
0
2016-09-26T20:39:38Z
[ "python", "html", "json" ]
how can i control modules in package to import in python?
39,707,315
<p>Consider an example,</p> <p>I have a package having list of modules:</p> <pre><code> /mypackage/ __init__.py mod1.py mod2.py mod3.py </code></pre> <p><code>prog1.py</code>: I would like to allow only <code>mod2</code> here <code>prog2</code>: allow <code>mod1,2</code></p> <p>If I write,</p> <pre><co...
-1
2016-09-26T15:56:27Z
39,707,396
<pre><code>from mypackage import mod2 </code></pre> <p>or</p> <pre><code>from mypackage import mod1, mod3 </code></pre>
3
2016-09-26T16:00:45Z
[ "python" ]
how can i control modules in package to import in python?
39,707,315
<p>Consider an example,</p> <p>I have a package having list of modules:</p> <pre><code> /mypackage/ __init__.py mod1.py mod2.py mod3.py </code></pre> <p><code>prog1.py</code>: I would like to allow only <code>mod2</code> here <code>prog2</code>: allow <code>mod1,2</code></p> <p>If I write,</p> <pre><co...
-1
2016-09-26T15:56:27Z
39,707,446
<p>I don't think that packages should control who and how can import them, basically packages should not know about their importers. However if you for some reason still thing this is a good idea, you can get a main filename by:</p> <pre><code>import __main__ main_file = __main__.__file__ </code></pre> <p>And then mo...
0
2016-09-26T16:03:41Z
[ "python" ]
Use of plot and curve in rpy2
39,707,359
<p>In R, I can run plot and curve to get the relationship between a predicted probability and the predictor variable by just running:</p> <pre><code>plot(outcome~survrate, data = d, ylab = "P(outcome = 1 | survrate)", xlab = "SURVRATE: Probability of Survival after 5 Years", xaxp = c(0, 95, 19)) curve(transform(coef(...
0
2016-09-26T15:58:27Z
39,708,025
<p>Use the accessor "R-operator" (<code>.ro</code> - see <a href="http://rpy2.readthedocs.io/en/version_2.8.x/vector.html#operators" rel="nofollow">http://rpy2.readthedocs.io/en/version_2.8.x/vector.html#operators</a>):</p> <pre><code>In [1]: from rpy2.robjects.vectors import FloatVector In [2]: FloatVector((1,2,3))....
1
2016-09-26T16:37:17Z
[ "python", "plot", "curve", "rpy2" ]
Authenticating with JWT token in Django
39,707,471
<p>I am beginner in Django and I am learning about JWT token from here.</p> <p><a href="http://getblimp.github.io/django-rest-framework-jwt/#rest-framework-jwt-auth" rel="nofollow">http://getblimp.github.io/django-rest-framework-jwt/#rest-framework-jwt-auth</a></p> <p>I have already set up in my settings.py.</p> <pr...
0
2016-09-26T16:05:01Z
39,741,420
<p>I know now. For my case, I am not okay only on web. I check from this link.</p> <p><a href="http://stackoverflow.com/questions/26906630/django-rest-framework-authentication-credentials-were-not-provided">Django Rest Framework - Authentication credentials were not provided</a></p> <p>It say I need to add </p> <pre...
0
2016-09-28T08:00:13Z
[ "python", "django", "jwt" ]
Testing external URLs in Django
39,707,524
<p>I'm currently having a hard time getting some of my Django tests to work. What I'm trying to do is test if a given URL (the REST API I want to consume) is up and running (returning status code 200) and later on if it's responding the expected values. However, all I get returned is a status code 404 (Page not found),...
0
2016-09-26T16:08:04Z
39,707,581
<p><code>self.client</code> is not a real HTTP client; it's the Django test client, which simulates requests to your own app for the purposes of testing. It doesn't make HTTP requests, and it only accepts a path, not a full URL.</p> <p>If you really needed to check that an external URL was up, you would need a proper ...
0
2016-09-26T16:12:02Z
[ "python", "django", "unit-testing", "testing" ]
How to run a command inside virtual environment using Python
39,707,585
<p>I have the virutalenv created and installed. I have also installed jsnapy tool inside my virutal env. </p> <p>This is the script that we are using:</p> <pre><code>Filename : venv.py import os os.system('/bin/bash --rcfile ~/TestAutomation/End2EndAutomation/bin/activate') os.system('End2EndAutomation/bin/jsnapy')...
0
2016-09-26T16:12:06Z
39,707,673
<p>Each call to <code>os.system()</code> will create a new bash instance and terminate the previous one. To run all the commands in one bash instance you could put all your commands inside a single bash script and call that from <code>os.system()</code></p> <p><strong>run.sh</strong></p> <pre><code>source ~/TestAutom...
0
2016-09-26T16:17:04Z
[ "python" ]
How to run a command inside virtual environment using Python
39,707,585
<p>I have the virutalenv created and installed. I have also installed jsnapy tool inside my virutal env. </p> <p>This is the script that we are using:</p> <pre><code>Filename : venv.py import os os.system('/bin/bash --rcfile ~/TestAutomation/End2EndAutomation/bin/activate') os.system('End2EndAutomation/bin/jsnapy')...
0
2016-09-26T16:12:06Z
39,709,190
<p>Two successive calls to <code>os.system()</code> will create two independent processes, one after the other. The second will run when the first finishes. Any effects of commands executed in the first process will have been forgotten and flushed when the second runs.</p> <p>You want to run the activation and the c...
0
2016-09-26T17:45:53Z
[ "python" ]
GitPython list all files affected by a certain commit
39,707,759
<p>I am using this for loop to loop through all commits:</p> <pre><code>repo = Repo("C:/Users/shiro/Desktop/lucene-solr/") for commit in list(repo.iter_commits()): print commit.files_list # how to do that ? </code></pre> <p>How can I get a list with the files affected from this specific commit ?</p>
0
2016-09-26T16:21:53Z
39,792,599
<p>I solved this problem for SCM Workbench. The important file is:</p> <p><a href="https://github.com/barry-scott/scm-workbench/blob/master/Source/Git/wb_git_project.py" rel="nofollow">https://github.com/barry-scott/scm-workbench/blob/master/Source/Git/wb_git_project.py</a></p> <p>Look at cmdCommitLogForFile() and it...
0
2016-09-30T13:22:16Z
[ "python", "gitpython" ]
ValueError: could not convert string to float: '[231.49377550490459]'
39,708,064
<p>I am trying to cast a python list into a float. This is the problem narrowed down:</p> <pre><code>loss = ['[228.55112815111235]', '[249.41649450361379]'] print(float(loss[0])) </code></pre> <p>And results in the error:</p> <pre><code>ValueError: could not convert string to float: '[231.49377550490459]' </code></...
-4
2016-09-26T16:39:38Z
39,708,097
<p>Strip the brackets.</p> <pre><code>float(loss[0].replace('[', '').replace(']', '')) </code></pre>
1
2016-09-26T16:41:25Z
[ "python" ]
ValueError: could not convert string to float: '[231.49377550490459]'
39,708,064
<p>I am trying to cast a python list into a float. This is the problem narrowed down:</p> <pre><code>loss = ['[228.55112815111235]', '[249.41649450361379]'] print(float(loss[0])) </code></pre> <p>And results in the error:</p> <pre><code>ValueError: could not convert string to float: '[231.49377550490459]' </code></...
-4
2016-09-26T16:39:38Z
39,708,121
<p>You can use string slicing if there is always just one element in your string list.</p> <pre><code>loss = ['[228.55112815111235]', '[249.41649450361379]'] print(float(loss[0][1:-1])) </code></pre>
0
2016-09-26T16:42:27Z
[ "python" ]
ValueError: could not convert string to float: '[231.49377550490459]'
39,708,064
<p>I am trying to cast a python list into a float. This is the problem narrowed down:</p> <pre><code>loss = ['[228.55112815111235]', '[249.41649450361379]'] print(float(loss[0])) </code></pre> <p>And results in the error:</p> <pre><code>ValueError: could not convert string to float: '[231.49377550490459]' </code></...
-4
2016-09-26T16:39:38Z
39,708,145
<p>That is because your <code>float</code> value is encapsulated within brackets. And you'll get <code>ValueError</code> because that is not valid float value. In order to convert it, you have to firstly remove them. For example:</p> <pre><code>&gt;&gt;&gt; my_val = '[228.55112815111235]' &gt;&gt;&gt; print float(my_v...
0
2016-09-26T16:44:47Z
[ "python" ]
ValueError: could not convert string to float: '[231.49377550490459]'
39,708,064
<p>I am trying to cast a python list into a float. This is the problem narrowed down:</p> <pre><code>loss = ['[228.55112815111235]', '[249.41649450361379]'] print(float(loss[0])) </code></pre> <p>And results in the error:</p> <pre><code>ValueError: could not convert string to float: '[231.49377550490459]' </code></...
-4
2016-09-26T16:39:38Z
39,708,262
<p>If you want to convert the list values to floats you can use list comprehension:</p> <pre><code>loss = [float(loss[i][1:-1]) for i in range(len(loss))] </code></pre> <p>Then your loss list will look like this:</p> <pre><code>[228.55112815111235, 249.4164945036138] </code></pre>
0
2016-09-26T16:50:56Z
[ "python" ]
Ember serializer customization for alternate url
39,708,111
<p>I am a newbie to ember. So here is what i faced. I got backend RESTAPI written in python/Django. It provides following json response on <code>/api/works/</code></p> <pre><code>[ { "id": 17, "title": "about us", "description": "some project", "owner": "admin" }, { "id": 19, "title": "test1 pr...
0
2016-09-26T16:42:05Z
39,710,804
<p>The serializer are used to customize the loading and saving (or serialization and deserialization) of data.</p> <p>To customize the URLs you must use an Adapter,(e.g. <a href="http://emberjs.com/api/data/classes/DS.RESTAdapter.html" rel="nofollow" title="Adapter">RESTAdapter</a> is my most used adapter).</p> <p>Th...
1
2016-09-26T19:25:48Z
[ "python", "json", "django", "rest", "ember.js" ]
Global variables in a Python module spontaneously reset
39,708,118
<p>I have part of a program written in Python 3.5 and started by testing the first two modules. I managed to isolate a problem in one of the modules where it appears that two global variables are switching back to their original values for no reason that I can understand. One of these global variables (<code>event_coun...
1
2016-09-26T16:42:18Z
39,730,609
<p>Let's take a look at your two-module example step-by-step. The behavior there is expected, but initially confusing and probably explains what is going on pretty well in the other cases.</p> <p>If you run <code>a</code> as a script, it is not imported as <code>a</code> into <code>sys.modules</code>, but rather as <c...
1
2016-09-27T17:10:10Z
[ "python", "python-3.x" ]
TypeError: can't multiply sequence by non-int of type 'float' (python 2.7)
39,708,133
<p>I have a dataframe <code>t_unit</code>, which is the result of a <code>pd.read_csv()</code> function.</p> <pre><code>datetime B18_LR_T B18_B1_T 24/03/2016 09:00 21.274 21.179 24/03/2016 10:00 19.987 19.868 24/03/2016 11:00 21.632 21.417 24/03/2016 12:00 26.285 24.779 24/03/2016 13:00 26.897...
0
2016-09-26T16:43:52Z
39,710,267
<p>There is problem some column is not numeric. You can check <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.dtypes.html" rel="nofollow"><code>dtypes</code></a>:</p> <pre><code>print (t_unit.dtypes) B18_LR_T float64 B18_B1_T float64 ext_T object dtype: object </code></pre>...
0
2016-09-26T18:52:21Z
[ "python", "pandas", "time-series", "resampling", "quantile" ]
error while installing django
39,708,136
<p>I am trying to learn Django framework. I have windows machine and on that I have installed virtual machine (oracle VM VirtualBox manager). I have python installed on that.</p> <p>I dont see pip installed on this VM. so i tried to install django via below:</p> <pre><code> wget https://www.djangoproject.com/download...
0
2016-09-26T16:44:11Z
39,708,488
<p>why not just download from <a href="https://github.com/django/django/archive/master.tar.gz" rel="nofollow">github repo</a></p> <p>in that way this will work </p> <p><code>wget https://github.com/django/django/archive/master.tar.gz</code></p>
-1
2016-09-26T17:04:11Z
[ "python", "django" ]
error while installing django
39,708,136
<p>I am trying to learn Django framework. I have windows machine and on that I have installed virtual machine (oracle VM VirtualBox manager). I have python installed on that.</p> <p>I dont see pip installed on this VM. so i tried to install django via below:</p> <pre><code> wget https://www.djangoproject.com/download...
0
2016-09-26T16:44:11Z
39,708,965
<p>(I am assuming you use Ubuntu on this VM) </p> <p>Just install pip with the following command: </p> <pre><code>sudo apt-get install python-pip python-dev build-essential </code></pre>
-1
2016-09-26T17:31:53Z
[ "python", "django" ]
error while installing django
39,708,136
<p>I am trying to learn Django framework. I have windows machine and on that I have installed virtual machine (oracle VM VirtualBox manager). I have python installed on that.</p> <p>I dont see pip installed on this VM. so i tried to install django via below:</p> <pre><code> wget https://www.djangoproject.com/download...
0
2016-09-26T16:44:11Z
39,709,719
<p>Get pip installed and working and then install it using pip as suggested </p> <p><strong>Official instructions</strong> [check out instructions][1] Per <a href="http://www.pip-installer.org/en/latest/installing.html" rel="nofollow">http://www.pip-installer.org/en/latest/installing.html</a>:</p> <p>Download get-pip...
1
2016-09-26T18:19:10Z
[ "python", "django" ]
How can I not read the last line of a csv file if it has simply 1 column in Python?
39,708,183
<p>I have 2 csv files with 4 columns like these.</p> <pre><code>1 3 6 8\n 1 3 7 2\n 7 9 1 3\n 9 2 4 1\n \n 1 8 2 3\n </code></pre> <p>I only want to read rows with at least 2 columns because the row with only \n, it isn´t useful.</p> <p>Currently, I am reading...
0
2016-09-26T16:47:31Z
39,708,245
<p>You can test the <em>truthy</em> value of the line after <em>stripping</em> the whitespace character. An empty string will have a falsy value which you can avoid by processing in an <code>if</code> block:</p> <pre><code>for line in f: line = line.strip("\n") if line: # empty string will be falsy ...
1
2016-09-26T16:50:04Z
[ "python", "python-2.7", "csv", "readfile" ]
How can I not read the last line of a csv file if it has simply 1 column in Python?
39,708,183
<p>I have 2 csv files with 4 columns like these.</p> <pre><code>1 3 6 8\n 1 3 7 2\n 7 9 1 3\n 9 2 4 1\n \n 1 8 2 3\n </code></pre> <p>I only want to read rows with at least 2 columns because the row with only \n, it isn´t useful.</p> <p>Currently, I am reading...
0
2016-09-26T16:47:31Z
39,708,375
<p>If they are legitimately comma-separated csv files, try the csv module. You will still have to eliminate empty rows, as in the other answers. For this, you can test for an empty list (which is a falsey value when evaluated as an expression in an if statement).</p> <pre><code>import csv with open('filename.csv' as ...
2
2016-09-26T16:57:19Z
[ "python", "python-2.7", "csv", "readfile" ]
How can I not read the last line of a csv file if it has simply 1 column in Python?
39,708,183
<p>I have 2 csv files with 4 columns like these.</p> <pre><code>1 3 6 8\n 1 3 7 2\n 7 9 1 3\n 9 2 4 1\n \n 1 8 2 3\n </code></pre> <p>I only want to read rows with at least 2 columns because the row with only \n, it isn´t useful.</p> <p>Currently, I am reading...
0
2016-09-26T16:47:31Z
39,708,416
<p>You can just quit the loop when you hit the blank line.</p> <pre><code>if not line.strip(): break </code></pre>
2
2016-09-26T17:00:11Z
[ "python", "python-2.7", "csv", "readfile" ]
Function with multiple options of returns
39,708,247
<p>Sorry, if this question was already answered, I couldn't think of a better way to describe this problem :/</p> <p>Let's say I have a function like this:</p> <pre><code>def func(arg): if arg something: return a, b, c, d else: return False </code></pre> <p>So, when i call this function like ...
2
2016-09-26T16:50:13Z
39,708,266
<p>You can just test the returned value first, then unpack:</p> <pre><code>value = func(arg) if value: a, b, c, d = value </code></pre> <p>Of course, you'll have to deal with what happens in the calling function when <code>abcd</code> don't get assigned. </p>
2
2016-09-26T16:51:09Z
[ "python", "function", "return" ]
Function with multiple options of returns
39,708,247
<p>Sorry, if this question was already answered, I couldn't think of a better way to describe this problem :/</p> <p>Let's say I have a function like this:</p> <pre><code>def func(arg): if arg something: return a, b, c, d else: return False </code></pre> <p>So, when i call this function like ...
2
2016-09-26T16:50:13Z
39,708,308
<p>Yes it will raise a <code>ValueError</code>. You can take care of that by wrapping the assignment with a <code>try-except</code> statement:</p> <pre><code>try: a, b, c, d = func(arg) except ValueError: # pass or do something else </code></pre> <p>Note that you can also check the validation of your returned...
2
2016-09-26T16:53:21Z
[ "python", "function", "return" ]
Function with multiple options of returns
39,708,247
<p>Sorry, if this question was already answered, I couldn't think of a better way to describe this problem :/</p> <p>Let's say I have a function like this:</p> <pre><code>def func(arg): if arg something: return a, b, c, d else: return False </code></pre> <p>So, when i call this function like ...
2
2016-09-26T16:50:13Z
39,708,327
<p>Functions with heterogeneous return types are awkward for the caller.</p> <p>Can you refactor? If the <code>else</code> case is a failure mode, consider using exceptions for this case - python is not golang. </p>
1
2016-09-26T16:54:21Z
[ "python", "function", "return" ]
Function with multiple options of returns
39,708,247
<p>Sorry, if this question was already answered, I couldn't think of a better way to describe this problem :/</p> <p>Let's say I have a function like this:</p> <pre><code>def func(arg): if arg something: return a, b, c, d else: return False </code></pre> <p>So, when i call this function like ...
2
2016-09-26T16:50:13Z
39,708,334
<p>Yes, this would cause a problem. Generally you don't want to do something like this, it often leads to unexpected errors later on that are difficult to catch. Python allows you to break the rules by returning whatever you want, but you should only do it if you have a good reason. As a general rule, your functions ...
2
2016-09-26T16:54:40Z
[ "python", "function", "return" ]
Function with multiple options of returns
39,708,247
<p>Sorry, if this question was already answered, I couldn't think of a better way to describe this problem :/</p> <p>Let's say I have a function like this:</p> <pre><code>def func(arg): if arg something: return a, b, c, d else: return False </code></pre> <p>So, when i call this function like ...
2
2016-09-26T16:50:13Z
39,708,454
<p>How about instead of having mixed return types, just refactor to require the function to have a truthy argument and raise an Error otherwise? This way the Error will be raised inside the function and not on assignment, which seems clearer to me.</p> <pre><code>def func(arg): if not arg: raise ValueError...
1
2016-09-26T17:02:20Z
[ "python", "function", "return" ]
Python AES Decrypt printed with encrypted text
39,708,284
<p>i got a problem with decryption text file that say 'i want to be clear text file'.</p> <p>the encryption is good work but when i decrypt it's get mixed, clear text and encrypt data.</p> <p>now i know me writing is a little amateurish.. but i need your help to get it through. i tried to build it in def functions bu...
0
2016-09-26T16:52:18Z
39,711,171
<p>There are two major mistakes within the code:</p> <ul> <li>the IV needs to be stripped off before (and used during) decryption instead of adding it again to the plaintext; currently your plaintext starts with the IV and then a decrypted IV;</li> <li>the padding needs to be removed after decryption, not before, curr...
1
2016-09-26T19:47:22Z
[ "python", "encryption", "cryptography", "aes" ]
Compare between 2 Excel files and give difference based on key column
39,708,455
<p>I have 2 excel files (which can be coverted to CSV).</p> <pre><code>File 1: Last Name First Name id(10 digit) email age course abc def 1234567890 axd 00 y2k bcd efg 9012345875 bxe 11 k2z cnn nbc 5678912345 cxn 00 z2k File 2: Group_ID ...
-1
2016-09-26T17:02:27Z
39,711,090
<p>Assuming that you read file 1 and file 2 into pandas data frames df1 and df2,</p> <p>df1.loc[df1['id'] != df2['Person_ID']]</p>
0
2016-09-26T19:41:59Z
[ "python", "csv", "pandas" ]
Basic input with keydown/keyup in Python
39,708,532
<p>i am currently trying to create a little game in python, but as i try to work with keydown/keyup events my system would interpret both events as one. I wrote a simple script to monitor the events that are created by 'pygame'(a module to simplify making games in python) and as i press down a key it instantly shows bo...
0
2016-09-26T17:07:23Z
39,778,081
<p>Your issue with the KEYUP event immediately after the the KEYDOWN event is caused by the line <code>display = pygame.display.set_mode((800, 600))</code> being within your main loop. The program is creating a new display on every iteration of the loop. This line, needs to be placed before the main loop as it should b...
0
2016-09-29T19:01:07Z
[ "python", "events", "pygame" ]
django request.POST data is empty but works with other similar form
39,708,559
<p>I'm new to django and I was following a tutorial from django on how to process POST form data with a model</p> <p><a href="https://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view" rel="nofollow">https://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view</a></p> <p>I was able to d...
-2
2016-09-26T17:08:54Z
39,708,866
<p>You seem to be using completely different field names in the template from the form - your form has <code>regName</code>, <code>regEmail</code> etc, but your template has <code>usernamesignup</code> etc.</p> <p>In any case, you should be using the form object itself to output the fields:</p> <pre><code>{{ form.reg...
1
2016-09-26T17:25:58Z
[ "python", "html", "django", "forms", "post" ]
Find elements based on neighbor values
39,708,568
<p>I would like to know if there is an efficient way to find indexes of elements next to a specific value in a Numpy array.</p> <p>How can I find indexes of all the elements that are equal to 1 and that are next to a 0 in this array A ? Without a loop checking for the value of the 8 surrounded elements for each eleme...
2
2016-09-26T17:09:43Z
39,709,106
<p>Here's one approach using binary erosion:</p> <pre><code>import numpy as np from scipy import ndimage eroded = ndimage.binary_erosion(A, np.eye(3)) diff = (A - eroded).astype(np.bool) print(repr(diff)) # array([[False, False, False, False, False, False], # [False, True, True, True, True, False], # ...
2
2016-09-26T17:40:04Z
[ "python", "arrays", "numpy", "edge-detection" ]
How to insert children of one xml node in another xml node with python
39,708,647
<p>I have follwing xml file:</p> <pre><code>&lt;root&gt; &lt;nodeA&gt; &lt;childrens_A&gt; &lt;/nodeA&gt; &lt;nodeB&gt; &lt;childrens_B&gt; &lt;/nodeB&gt; &lt;nodeA&gt; &lt;childrens_A&gt; &lt;/nodeA&gt; &lt;nodeB&gt; &lt;childrens_B&gt; &lt;/nodeB&gt; &lt;/root&gt; </code></pre> <p>I want get somethi...
0
2016-09-26T17:14:34Z
39,753,303
<p>Looks like i find solution:</p> <pre><code>from xml.etree import ElementTree as et tr = et.parse(path_in) root = tr.getroot() for child in root.getchildren(): if child.tag == 'nodeB': sub = child.getchildren() i = root.getchildren().index(child) root.getchildren(...
0
2016-09-28T16:45:53Z
[ "python", "xml", "python-2.7" ]
How does __setattr__ work with class attributes?
39,708,662
<p>I am trying to understand how exactly __setattr__ works with class attributes. This question came about when I had attempted to override __setattr__ to prevent attributes from being written to in a simple class.</p> <p>My first attempt used instance level attributes as follows:</p> <pre><code>class SampleClass(obj...
2
2016-09-26T17:15:19Z
39,708,766
<p>Unless I'm missing something here, the answer is quite obvious: the first case has an attribute assignment which triggers the <code>__setattr__</code> method, in the line:</p> <pre><code>self.PublicAttribute1 = "attribute" </code></pre> <p>But the second case has no such attribute assignment. </p>
0
2016-09-26T17:21:10Z
[ "python" ]
How does __setattr__ work with class attributes?
39,708,662
<p>I am trying to understand how exactly __setattr__ works with class attributes. This question came about when I had attempted to override __setattr__ to prevent attributes from being written to in a simple class.</p> <p>My first attempt used instance level attributes as follows:</p> <pre><code>class SampleClass(obj...
2
2016-09-26T17:15:19Z
39,708,827
<p><code>__setattr__()</code> is called whenever a value is assigned to any of the class's property. Even if the property is initialized in the <code>__init__()</code>, it will make call to <code>__setattr__()</code>. Below is the example to illustrate that:</p> <pre><code>&gt;&gt;&gt; class X(object): ... def __i...
0
2016-09-26T17:24:06Z
[ "python" ]
How does __setattr__ work with class attributes?
39,708,662
<p>I am trying to understand how exactly __setattr__ works with class attributes. This question came about when I had attempted to override __setattr__ to prevent attributes from being written to in a simple class.</p> <p>My first attempt used instance level attributes as follows:</p> <pre><code>class SampleClass(obj...
2
2016-09-26T17:15:19Z
39,708,928
<p>The below can be found in the python documentation</p> <blockquote> <p>Attribute assignments and deletions update the instance’s dictionary, never a class’s dictionary. If the class has a __setattr__() or __delattr__() method, this is called instead of updating the instance dictionary directly.</p> </blockquo...
2
2016-09-26T17:29:33Z
[ "python" ]
How does __setattr__ work with class attributes?
39,708,662
<p>I am trying to understand how exactly __setattr__ works with class attributes. This question came about when I had attempted to override __setattr__ to prevent attributes from being written to in a simple class.</p> <p>My first attempt used instance level attributes as follows:</p> <pre><code>class SampleClass(obj...
2
2016-09-26T17:15:19Z
39,709,070
<p><code>__setattr__</code> is only invoked on <em>instances</em> of a class and not the actual class itself. However, the class is still an object, so when setting the attribute of the class the <code>__setattr__</code> of the class of the class is invoked. </p> <p>To change how attributes are set on classes you need...
2
2016-09-26T17:38:10Z
[ "python" ]
How does __setattr__ work with class attributes?
39,708,662
<p>I am trying to understand how exactly __setattr__ works with class attributes. This question came about when I had attempted to override __setattr__ to prevent attributes from being written to in a simple class.</p> <p>My first attempt used instance level attributes as follows:</p> <pre><code>class SampleClass(obj...
2
2016-09-26T17:15:19Z
39,709,154
<p>The <code>__setattr__</code> method defined in a class is only called for attribute assignments on <em>istances</em> of the class. It is not called for class variables, since they're not being assigned on an instance of the class with the method.</p> <p>Of course, classes are instances too. They're instances of <co...
3
2016-09-26T17:43:01Z
[ "python" ]
How does __setattr__ work with class attributes?
39,708,662
<p>I am trying to understand how exactly __setattr__ works with class attributes. This question came about when I had attempted to override __setattr__ to prevent attributes from being written to in a simple class.</p> <p>My first attempt used instance level attributes as follows:</p> <pre><code>class SampleClass(obj...
2
2016-09-26T17:15:19Z
39,709,237
<p><code>__setattr__()</code> applies only to instances of the class. In your second example, when you define <code>PublicAttribute1</code>, you are defining it on the class; there's no instance, so <code>__setattr__()</code> is not called.</p> <p>N.B. In Python, things you access using the <code>.</code> notation are...
1
2016-09-26T17:48:28Z
[ "python" ]
Capture files that have been modified in the past x days in Python
39,708,674
<p>I'm using the below script to re-encode my existing media files to MP4 using the HandBrake CLI. It's going to be a long process, so I'd like to have a way to capture files that have been created in the past 7 days, as well as the other filters (on file extensions), so that new content can be updated, while older con...
1
2016-09-26T17:15:47Z
39,709,112
<p><code>os.path.getmtime(filename)</code> will give you the modification time in seconds since the epoch.</p> <p>Use the <code>datetime</code> module to convert it to a <code>datetime</code> object, and compare it as usual.</p> <pre><code>import datetime import os ONE_WEEK_AGO = datetime.datetime.today() - datetime...
1
2016-09-26T17:40:24Z
[ "python", "handbrake" ]
Read list of lists from text file and join and decode
39,708,736
<p>I have a list of lists in a text file that contains non encoded unicode. Python is recognising the object being read in as a list without me doing anything like a <code>json.loads()</code>statement direct from the text file.</p> <p>When I try and read all lines of the text file and then do a for loop to iterate thr...
0
2016-09-26T17:19:06Z
39,710,607
<p>Maybe something like next code snippet?</p> <pre><code>listInput = [['Alexis S\xe1nchez', 'Alexis', 'S\xe1nchez', 'Forward', 'Arsenal', '13', '25244'], ['H\xe9ctor Beller\xedn', 'H\xe9ctor', 'Beller\xedn', 'Defender', 'Arsenal', '13', '125211'], ['Libor Koz\xe1k', 'Libor', 'Koz\xe1k', 'Forward', 'Aston Villa', ...
0
2016-09-26T19:13:42Z
[ "python", "unicode" ]
Making pygame sprites disappear in python
39,709,065
<p>I am working on a rpg game and I want my playbutton to disappear as soon as it was pressed. Is there a method of which I can do that? I have different game states they are: GAME, MENU, START The playbutton will appear on the START game state and I want it to disappear when it is pressed or when the game state change...
0
2016-09-26T17:37:52Z
39,710,944
<p>If the button is truly a sprite, you can:</p> <ul> <li>Add the sprite to a group called Buttons.</li> <li>Render the Buttons on the screen.</li> <li>Use the kill() method to remove the sprite from the Buttons group.</li> <li>Re-render the screen on the next round.</li> </ul> <p><a href="http://pygame.org/docs/ref/...
0
2016-09-26T19:33:51Z
[ "python", "pygame" ]
Making pygame sprites disappear in python
39,709,065
<p>I am working on a rpg game and I want my playbutton to disappear as soon as it was pressed. Is there a method of which I can do that? I have different game states they are: GAME, MENU, START The playbutton will appear on the START game state and I want it to disappear when it is pressed or when the game state change...
0
2016-09-26T17:37:52Z
39,711,223
<p>To remove something from the screen you need to draw something else over it. So the most basic answer would be to just stop rendering the button and start render other stuff over it.</p> <p>A great way to go about it is making all your visible objects inherit <a href="http://www.pygame.org/docs/ref/sprite.html#pyga...
0
2016-09-26T19:50:15Z
[ "python", "pygame" ]
Dictionary manipulation
39,709,147
<p>I have a dictionary of dictionaries which dialed down a notch or two looks like this:</p> <pre><code>a = {114907: {114905: 1.4351310915, 114908: 0.84635577943, 114861: 61.490648372}, 113820: {113826: 8.6999361654, 113819: 1.1412795216, 111068: 1.196494628...
4
2016-09-26T17:42:28Z
39,709,498
<pre><code># for each "primary key" for primary in a.keys(): # for each "sub-key" for sub_key in a[primary].keys(): # if the sub-key is also a primary key if sub_key in a.keys(): # assign to the subkey the value of its corresponding primary key a[primary][sub_key] = a[sub...
0
2016-09-26T18:05:56Z
[ "python", "python-3.x", "dictionary" ]
Dictionary manipulation
39,709,147
<p>I have a dictionary of dictionaries which dialed down a notch or two looks like this:</p> <pre><code>a = {114907: {114905: 1.4351310915, 114908: 0.84635577943, 114861: 61.490648372}, 113820: {113826: 8.6999361654, 113819: 1.1412795216, 111068: 1.196494628...
4
2016-09-26T17:42:28Z
39,709,930
<p>This should work</p> <pre><code>a = {114907: {114905: 1.4351310915, 114908: 0.84635577943, 114861: 61.490648372}, 113820: {113826: 8.6999361654, 113819: 1.1412795216, 111068: 1.1964946282, 117066: 1.5595617822, 113822: 1.195895...
1
2016-09-26T18:32:43Z
[ "python", "python-3.x", "dictionary" ]
Dictionary manipulation
39,709,147
<p>I have a dictionary of dictionaries which dialed down a notch or two looks like this:</p> <pre><code>a = {114907: {114905: 1.4351310915, 114908: 0.84635577943, 114861: 61.490648372}, 113820: {113826: 8.6999361654, 113819: 1.1412795216, 111068: 1.196494628...
4
2016-09-26T17:42:28Z
39,710,128
<p>How about this:</p> <pre><code>import itertools b ={} for k1,v1 in a.items(): for k2,v2 in v1.items(): if k2 in a: a[k2].pop(k1) a[k1].pop(k2) dest = dict(itertools.chain(a[k1].items(), a[k2].items())) #python 2.7 b[(k1,k2)] = dest print b </code></pre...
0
2016-09-26T18:43:58Z
[ "python", "python-3.x", "dictionary" ]
Dictionary manipulation
39,709,147
<p>I have a dictionary of dictionaries which dialed down a notch or two looks like this:</p> <pre><code>a = {114907: {114905: 1.4351310915, 114908: 0.84635577943, 114861: 61.490648372}, 113820: {113826: 8.6999361654, 113819: 1.1412795216, 111068: 1.196494628...
4
2016-09-26T17:42:28Z
39,712,237
<p>In Python3.x, <code>{}.keys()</code> returns a view. You can use set operations on a dict view.</p> <p>So your algorithm is somewhat simplified to:</p> <pre><code>outer=a.keys() deletions=set() new_a={} for k,di in a.items(): c=outer &amp; di.keys() if c: c=c.pop() if (c,k) not in deletion...
1
2016-09-26T20:55:56Z
[ "python", "python-3.x", "dictionary" ]
PySys ProcessMonitor timestamps use different formats on Windows and Linux
39,709,182
<p>We're using PySys partly for performance testing, including the ProcessMonitor class to monitor CPU and memory usage, and a part of our tests parses the timestamp in the first column of the ProcessMonitor output, which requires us knowing the exact format. We run our tests on both Windows and Linux and have found th...
0
2016-09-26T17:45:19Z
39,711,891
<p>This is an inconsistency in the framework as pointed out, thanks. I've added a defect to the project so it can be tracked there (<a href="https://sourceforge.net/p/pysys/bugs/15" rel="nofollow">https://sourceforge.net/p/pysys/bugs/15</a>) and we can take offline from SO. </p>
0
2016-09-26T20:33:19Z
[ "python", "performance-testing" ]
Sorting list of tuples of tuples
39,709,197
<pre><code>[((D,A),0.0),((D,C),0.0),((D,E),0.5)] </code></pre> <p>I need to sort the list as:</p> <pre><code>[((D,E),0.5),((D,A),0.0),((D,C),0.0)] </code></pre> <p>I have used the <code>sorted()</code> function and I am able to sort based on values <code>0.5, 0.0</code>... But I am not able to sort on the alphabetic...
-1
2016-09-26T17:46:15Z
39,709,308
<p>Use a tuple as the sort key with a negative on the float to reverse the order:</p> <pre><code>&gt;&gt;&gt; li=[(('D','A'),0.0),(('D','C'),0.0),(('D','E'),0.5)] &gt;&gt;&gt; sorted(li, key=lambda t: (-t[-1],t[0])) [(('D', 'E'), 0.5), (('D', 'A'), 0.0), (('D', 'C'), 0.0)] </code></pre> <p>If you cannot do negation (...
2
2016-09-26T17:52:56Z
[ "python", "python-3.x", "sorting" ]
Sorting list of tuples of tuples
39,709,197
<pre><code>[((D,A),0.0),((D,C),0.0),((D,E),0.5)] </code></pre> <p>I need to sort the list as:</p> <pre><code>[((D,E),0.5),((D,A),0.0),((D,C),0.0)] </code></pre> <p>I have used the <code>sorted()</code> function and I am able to sort based on values <code>0.5, 0.0</code>... But I am not able to sort on the alphabetic...
-1
2016-09-26T17:46:15Z
39,709,445
<p>Similarly, you could supply <code>sorted</code> with an iterable that is the result of another <code>sort</code>:</p> <pre><code>&gt;&gt;&gt; from operator import itemgetter &gt;&gt;&gt; t = [(('D','A'),0.0),(('D','C'),0.0),(('D','E'),0.5)] &gt;&gt;&gt; sorted(sorted(t), key=itemgetter(1), reverse=True) [(('D', 'E'...
1
2016-09-26T18:02:17Z
[ "python", "python-3.x", "sorting" ]
Proper response to Telegram.org "Error 500: RPC_SEND_FAIL"
39,709,349
<p>After sending an auth.sendCode method to the telegram.org server I am receiving the following in return:</p> <pre><code>{'MessageContainer': [{'msg': {u'bad_msg_notification': {u'bad_msg_seqno': 4, u'bad_msg_id': 6334696945916753920L, u'error_code': 35}}, 'seqno': 4, 'msg_id': 6334696948768376833L}, {'msg': {u'msgs...
1
2016-09-26T17:55:09Z
39,711,193
<p>The telegram.org servers are now responding as expected, no more <code>Error 500</code> conditions. All I did was wait a few hours, and updated from layer 54 to layer 55. I didn't see anything in the new layer that would cause the problem so I have to assume something was fixed on the server side. Time will tell.</p...
1
2016-09-26T19:48:19Z
[ "python", "api", "telegram" ]
How do I correctly use PCA followed by Logistic Regression?
39,709,355
<p>In the program, I am scanning a number of brain samples taken in a time series of 40 x 64 x 64 images every 2.5 seconds. The number of 'voxels' (3D pixels) in each image is thus ~ 168,000 ish (40 * 64 * 64), each of which is a 'feature' for an image sample. </p> <p>I thought of using Principle Component Analysis (P...
0
2016-09-26T17:55:22Z
39,709,786
<p>While I can't immediately find any error, you should try and test how the error behaves if you increase the <code>number of components</code>. Maybe there is some low variance information missing to give the logistic regression the edge it needs?</p> <p>The <code>99%</code> in PCA are more a guideline than fact.</p...
1
2016-09-26T18:22:36Z
[ "python", "pca", "logistic-regression" ]
Airflow DB session not providing any environement vabiable
39,709,370
<p>As an Airflow and Python newbie, even don't know if I'm asking the right question, but asking anyway. I've configured airflow on a CentOS system. Use remote MySql instance as the backend. In my code, need to get a number of Variables, the code looks like below: </p> <pre><code>import os from airflow.models import ...
0
2016-09-26T17:56:47Z
39,712,340
<p>Ok, finally got the problem resolved. What I've done is print out the query, and figured out the variable must be from some relational database table called variable. And dig into the backend DB, found the DB, made the comparation between it and the working one, and figured out that the "variable" table data missed....
0
2016-09-26T21:02:49Z
[ "python", "airflow" ]
Getting values from local variables in another procedure in Python 3.x
39,709,478
<p>I am currently learning how to program but I don't understand how to access a local variable from one procedure in order to use that variable's value in a different procedure. I am using Python version 3.5.2 and I have confirmed that the code will work when not divided into procedures. </p> <pre><code>#This program...
0
2016-09-26T18:04:53Z
39,709,736
<p>So just to show what the commenters said:</p> <pre><code>def evaluate(theage, theweight, themonth): if theage&lt;=25: print("Congratulations, the age is 25 or less!") elif theweight&gt;=128: print("Congratulations, the weight is 128 or more!") elif themonth=='April': print("Congr...
0
2016-09-26T18:19:58Z
[ "python", "python-3.x", "procedure", "local-variables" ]
How do I apply both bold and italics in python-docx?
39,709,527
<p>I'm working on making a dictionary. I'm using python-docx to put it into MS Word. I can easily make it bold, or italics, but can't seem to figure out how to do both. Here's the basics:</p> <pre><code>import docx word = 'Dictionary' doc = docx.Document() p = doc.add_paragraph() p.add_run(word).bold = True doc.sa...
2
2016-09-26T18:07:50Z
39,709,666
<p>The <code>add_run</code> method will return a new instance of <code>Run</code> each time it is called. You need create a single instance and then apply <code>italic</code> and <code>bold</code> </p> <pre><code>import docx word = 'Dictionary' doc = docx.Document() p = doc.add_paragraph() runner = p.add_run(word) ...
2
2016-09-26T18:16:07Z
[ "python", "docx", "python-docx" ]
SqlAlchemy Oracle DataTime format
39,709,575
<p>I use SqlAlchemy to query an Oracle database and store results in csv files.</p> <p>I would like to specify a global format for dates to be written like this : </p> <pre><code>'DD-MM-YYYY HH24:MI:SS'. </code></pre> <p>I have set NLS_DATE_FORMAT this way on the system.</p> <p>For exemple : </p> <pre><code>dateti...
0
2016-09-26T18:10:44Z
39,730,426
<p>I found a way to solve this issue.</p> <p>Yes, converting date to char with the appropriate formatting would work. But, in my case, SQL statement are provided by another module and I need to process more than a hundred tables.</p> <p>So, I decided to work with datas contained in the ResultProxy object returned by ...
0
2016-09-27T16:59:44Z
[ "python", "oracle", "datetime", "sqlalchemy" ]
Intuitive way to use 3D numpy arrays
39,709,579
<p>Lets take a simplistic example where I have the data array</p> <pre><code>A = np.asarray([[1,3], [2,4]]) </code></pre> <p>And this data is to be transformed into another form following a simple transformation: </p> <pre><code>Q = np.asarray([[-0.5,1], [1,0.5]]) B = np.dot(Q,np.dot(A,Q.T)) print B </code></pre> <...
1
2016-09-26T18:11:12Z
39,710,598
<p>I'm not sure I agree with your definition of "intuitive" - to me it seems more natural to represent the time index by the first dimension of the array. Since numpy arrays are <a href="https://en.wikipedia.org/wiki/Row-major_order" rel="nofollow">row-major</a> by default, this ordering of the dimensions will give you...
0
2016-09-26T19:13:17Z
[ "python", "numpy", "matrix-multiplication" ]
Intuitive way to use 3D numpy arrays
39,709,579
<p>Lets take a simplistic example where I have the data array</p> <pre><code>A = np.asarray([[1,3], [2,4]]) </code></pre> <p>And this data is to be transformed into another form following a simple transformation: </p> <pre><code>Q = np.asarray([[-0.5,1], [1,0.5]]) B = np.dot(Q,np.dot(A,Q.T)) print B </code></pre> <...
1
2016-09-26T18:11:12Z
39,710,847
<pre><code>In [91]: A=np.array([[1,3],[2,4]]) In [92]: Q=np.array([[-.5,1],[1,.5]]) In [93]: B=np.dot(Q,np.dot(A,Q.T)) In [94]: B Out[94]: array([[ 1.75, 2.75], [ 4. , 4.5 ]]) </code></pre> <p>The same calculation with <code>einsum</code>:</p> <pre><code>In [95]: np.einsum('ij,jk,kl',Q,A,Q) Out[95]: array...
1
2016-09-26T19:28:48Z
[ "python", "numpy", "matrix-multiplication" ]
Regex to extract two dates out of a date range
39,709,596
<p>I have a date range and I want to extract the two dates, this is an example string:</p> <pre><code>Sep 25-28, 2016 </code></pre> <p>and I'd like to have two regular expressions, one that matches:</p> <pre><code>Sep 25, 2016 </code></pre> <p>and the other that matches:</p> <pre><code>Sep 28, 2016 </code></pre> ...
1
2016-09-26T18:12:31Z
39,710,051
<p>Looking at your sample ranges, it looks like they follow this pattern:</p> <p><code>BEGIN_MONTH</code> <code>SPACE</code> <code>BEGIN_DAY</code> <code>DASH</code> <code>END_MONTH (optional)</code> <code>END_DAY</code> <code>COMMA</code> <code>SPACE</code> <code>YEAR</code></p> <p>From that, you want to generate tw...
0
2016-09-26T18:39:21Z
[ "python", "regex" ]
Regex to extract two dates out of a date range
39,709,596
<p>I have a date range and I want to extract the two dates, this is an example string:</p> <pre><code>Sep 25-28, 2016 </code></pre> <p>and I'd like to have two regular expressions, one that matches:</p> <pre><code>Sep 25, 2016 </code></pre> <p>and the other that matches:</p> <pre><code>Sep 28, 2016 </code></pre> ...
1
2016-09-26T18:12:31Z
39,714,720
<p>I would recommend using different regex for each possibility, and test them in order. This will result in a much simpler program (with test cases). Otherwise, the regex would be monstrous.</p> <pre><code>import re RE1 = re.compile(r"(\w+)\s*(\d+)\,\s+(\d+)") # Month day, year RE2 =...
0
2016-09-27T01:30:00Z
[ "python", "regex" ]
Identify groups of varying continuous numbers in a list
39,709,606
<p>In this <a href="https://stackoverflow.com/questions/2154249/identify-groups-of-continuous-numbers-in-a-list">other SO post</a>, a Python user asked how to group continuous numbers such that any sequences could just be represented by its start/end and any stragglers would be displayed as single items. The accepted a...
6
2016-09-26T18:13:20Z
39,710,121
<p>Here is a quickly written (and extremely ugly) answer:</p> <pre><code>def test(inArr): arr=inArr[:] #copy, unnecessary if we use index in a smart way result = [] while len(arr)&gt;1: #as long as there can be an arithmetic progression x=[arr[0],arr[1]] #take first two arr=arr[2:] #remove ...
1
2016-09-26T18:43:26Z
[ "python" ]
Identify groups of varying continuous numbers in a list
39,709,606
<p>In this <a href="https://stackoverflow.com/questions/2154249/identify-groups-of-continuous-numbers-in-a-list">other SO post</a>, a Python user asked how to group continuous numbers such that any sequences could just be represented by its start/end and any stragglers would be displayed as single items. The accepted a...
6
2016-09-26T18:13:20Z
39,712,094
<p>The <code>itertools</code> <a href="https://docs.python.org/2.6/library/itertools.html#recipes" rel="nofollow">pairwise recipe</a> is one way to solve the problem. Applied with <a href="https://docs.python.org/2.6/library/itertools.html#itertools.groupby" rel="nofollow"><code>itertools.groupby</code></a>, groups of ...
3
2016-09-26T20:47:06Z
[ "python" ]
Identify groups of varying continuous numbers in a list
39,709,606
<p>In this <a href="https://stackoverflow.com/questions/2154249/identify-groups-of-continuous-numbers-in-a-list">other SO post</a>, a Python user asked how to group continuous numbers such that any sequences could just be represented by its start/end and any stragglers would be displayed as single items. The accepted a...
6
2016-09-26T18:13:20Z
39,712,481
<p>You can create an iterator to help grouping and try to pull the next element from the following group which will be the end of the previous group:</p> <pre><code>def ranges(lst): it = iter(lst) next(it) # move to second element for comparison grps = groupby(lst, key=lambda x: (x - next(it, -float("inf"...
1
2016-09-26T21:12:51Z
[ "python" ]
Plotting function of (x,y) with 3D plot
39,709,636
<p>I have a function that takes one 2D vector and returns pdf (a scalar) of that point.</p> <p>As an illustration, <code>myPDF( np.array[4,4] )</code> returns a single pdf value at &lt;4,4>. This function cannot take a list of vectors, and it only accepts one 2D vector as an argument. </p> <p>Now I want to plot this...
0
2016-09-26T18:14:40Z
39,714,156
<p>Use <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.apply_along_axis.html" rel="nofollow"><code>apply_along_axis</code></a></p> <pre><code>xy = np.stack(np.mgrid[-5:5,-5:5], axis=-1) # xy[0,0] = x, y z = np.apply_along_axis(myPDF, axis=-1, arr=xy) # z[0,0] = myPDF(xy[0,0]) </code></pre>
1
2016-09-27T00:07:13Z
[ "python", "numpy", "plot", "scipy" ]
pip3.5 install getting variables from else where causing bad interpreter error
39,709,647
<p>I have many versions of <code>python</code> and also <code>pip</code> and <code>pip3.5</code> in </p> <pre><code>$ pwd /home/bli1/py/python3.5/bin </code></pre> <p>In my <code>.bashrc</code> I have:</p> <p><code>export PATH=${HOME}/py/python3.5/bin:$PATH</code></p> <p>I can run <code>python3.5</code> fine</p> <...
0
2016-09-26T18:15:04Z
39,709,888
<p>It seems like you've copied Python binaries from another machine.</p> <p>Python script endpoints contains shebangs that points to interpreter version which should be used by given script. </p> <p>You may verify shebang used by <code>pip3.5</code> those by running <code>cat $(which pip3.5)</code> in shell. If path ...
1
2016-09-26T18:30:10Z
[ "python", "bash", "python-wheel" ]
How to constructing url in start_urls list in scrapy framework python
39,709,687
<p>I am new to scrapy and python.<br> In my case:</p> <h2>Page A:</h2> <pre><code>http://www.example.com/search?keyword=city&amp;style=1&amp;page=1 http://www.example.com/search?keyword=city&amp;style=1&amp;page=2 http://www.example.com/search?keyword=city&amp;style=1&amp;page=3 </code></pre> <p>Rules is: </p...
0
2016-09-26T18:17:23Z
39,709,857
<p>the <a href="http://doc.scrapy.org/en/latest/topics/spiders.html#scrapy.spiders.Spider.start_requests" rel="nofollow"><code>start_requests</code></a> method is what you need. After that, keep passing the requests and parse the response bodies on callback methods.</p> <pre><code>class MySpider(Spider): name = 'e...
2
2016-09-26T18:27:40Z
[ "python", "regex", "scrapy" ]
Python - tlsv1 alert protocol version error in Docker client connection
39,709,781
<p>I'm using <a href="https://docker-py.readthedocs.io/en/latest/api/" rel="nofollow">Docker-py</a> and <a href="https://github.com/d11wtq/dockerpty" rel="nofollow">dockerpty</a> in order to <code>exec</code> commands using the <code>Docker</code> Python API. </p> <p>The code it's pretty simple:</p> <pre><code>contai...
1
2016-09-26T18:21:58Z
39,715,026
<p>In some older versions of Python, <code>ssl.PROTOCOL_TLSv1_2</code> isn't available. You can easily check by attempting to import it from the Python console inside the container: </p> <pre><code>root@57c6d8b01861:/# python Python 2.7.8 (default, Nov 26 2014, 22:28:51) &gt;&gt;&gt; import ssl &gt;&gt;&gt; ssl.PROTO...
1
2016-09-27T02:17:52Z
[ "python", "bash", "ssl", "docker" ]
Keyword Extraction in Python_RAKE
39,709,791
<p>I am a novice user and puzzled over the following otherwise simple "loop" problem. I have a local dir with x number of files (about 500 .txt files). I would like to extract the corresponding keywords from each unique file using RAKE for Python. I've reviewed the documentation for RAKE; however, the suggested code in...
0
2016-09-26T18:22:50Z
39,712,805
<p>Create a list of filenames you want to process:</p> <pre><code>filenames = [ 'data/docs/fao_test/w2167e.txt', 'some/other/folder/filename.txt', etc... ] </code></pre> <p>If you don't want to hardcode all the names, you can use the <code>glob</code> module to collect filenames by wildcards.</p> <p>Crea...
0
2016-09-26T21:35:39Z
[ "python", "rake", "keyword" ]
python + linux + not killing subprocess issues
39,709,827
<p>I am trying to find out a list of files within a directory path, which were created within the past 'n' minutes, using subprocess.popen with 'find' linux command.</p> <pre><code>def Subprocessroutine(n,path): argf='find '+str(path)+' -maxdepth 1 -mmin -'+str(n)+' -type f -printf "\n%AD %AT %p" | sort' p=s...
0
2016-09-26T18:25:14Z
39,710,277
<p>Based on your code, the only thing that "did not work" was the fact that dead links cause it to throw an <code>OSError</code>. I have modified it to the following:</p> <pre><code>#!/usr/bin/env python import os import time import datetime dirpath = "./" for p, ds, fs in os.walk(dirpath): for fn in fs: ...
0
2016-09-26T18:52:44Z
[ "python", "linux", "subprocess", "os.path" ]
Python - Comparing files delimiting characters in line
39,709,881
<p>there. I'm a begginer in python and I'm struggling to do the following:</p> <p>I have a file like this (+10k line):</p> <pre><code>EgrG_000095700 /product="ubiquitin carboxyl terminal hydrolase 5" EgrG_000095800 /product="DNA polymerase epsilon subunit 3" EgrG_000095850 /product="crossover junction endonuclease EM...
0
2016-09-26T18:29:32Z
39,710,050
<p>I'd store the ids from <code>f2</code> in a set and then check <code>f1</code> against that.</p> <pre><code>id_set = set() with open('eg_es_final_ids') as f2: for line in f2: id_set.add(line[:-2]) #get rid of the .1 with open('egranulosus_v3_2014_05_27.tsv') as f1: with open('res.tsv', 'w') as fr: ...
4
2016-09-26T18:39:12Z
[ "python", "python-2.7", "bioinformatics", "text-manipulation" ]
Python - Comparing files delimiting characters in line
39,709,881
<p>there. I'm a begginer in python and I'm struggling to do the following:</p> <p>I have a file like this (+10k line):</p> <pre><code>EgrG_000095700 /product="ubiquitin carboxyl terminal hydrolase 5" EgrG_000095800 /product="DNA polymerase epsilon subunit 3" EgrG_000095850 /product="crossover junction endonuclease EM...
0
2016-09-26T18:29:32Z
39,710,069
<p>f2 is a list of lines in file-2. Where are you iterating over the list, like you are doing for lines in file-1 (f1). That seems to be the problem. </p>
0
2016-09-26T18:40:20Z
[ "python", "python-2.7", "bioinformatics", "text-manipulation" ]
Python - Comparing files delimiting characters in line
39,709,881
<p>there. I'm a begginer in python and I'm struggling to do the following:</p> <p>I have a file like this (+10k line):</p> <pre><code>EgrG_000095700 /product="ubiquitin carboxyl terminal hydrolase 5" EgrG_000095800 /product="DNA polymerase epsilon subunit 3" EgrG_000095850 /product="crossover junction endonuclease EM...
0
2016-09-26T18:29:32Z
39,710,205
<pre><code>with open('egranulosus_v3_2014_05_27.txt', 'r') as infile: line_storage = {} for line in infile: data = line.split() key = data[0] value = line.replace('\n', '') line_storage[key] = value with open('eg_es_final_ids.txt', 'r') as infile, open('my_output.txt', 'w') as o...
0
2016-09-26T18:48:20Z
[ "python", "python-2.7", "bioinformatics", "text-manipulation" ]
Use LOAD DATA LOCAL INFILE on python with dynamic tables
39,710,169
<p>I am trying to use a query directly on python to update my database, but I need to do a lot of time in different table:</p> <pre><code>def load_data(self, path, table): print table print path cursor = self.mariadb_connection.cursor() cursor.execute(" LOAD DATA LOCAL INFILE %s INTO TABLE %s" ...
-1
2016-09-26T18:46:25Z
39,770,464
<p>Below follow the solution that I found:</p> <pre><code>cursor = self.mariadb_connection.cursor() cursor.execute("LOAD DATA LOCAL INFILE % s" "INTO TABLE " + str(table) + " " "FIELDS TERMINATED BY ',' " "ENCLOSED BY '\"' " "LINES TERMINATED BY '\n' " ...
0
2016-09-29T12:32:39Z
[ "python", "mysql" ]
How would you generate and store a unique ID to a text file based off of a user input?
39,710,177
<p>I'm looking to use user input names to create a unique ID for registration purposes. First, in the code, I ask them for both of their names:</p> <pre><code> Forename = str(input("Enter your first name: ")) Surname = str(input("Enter your surname: ")) (UID) = Forename[0], Surname[0],"0000" print (UID...
-2
2016-09-26T18:46:46Z
39,710,302
<p>As a starting point I'd suggest something like this:</p> <pre><code># input returns type `str` so we do not need to cast this manually to string first_name = input("Enter your first name: ") name = input("Enter your surname: ") # let's assume there are already three users # you need to implement a own routine to d...
0
2016-09-26T18:54:43Z
[ "python" ]
Finding first derivative using DFT in Python
39,710,215
<p>I want to find the first derivative of <code>exp(sin(x))</code> on the interval <code>[0, 2/pi]</code> using a discrete Fourier transform. The basic idea is to first evaluate the DFT of <code>exp(sin(x))</code> on the given interval, giving you say <code>v_k</code>, followed by computing the inverse DFT of <code>ikv...
0
2016-09-26T18:48:52Z
39,920,148
<p>Turns out the problem is that <code>np.zeros</code> gives you an array of real zeroes and not complex ones, hence the assignments after that don't change anything, as they are imaginary.</p> <p>Thus the solution is quite simply</p> <pre><code>import numpy as np N=100 xmin=0 xmax=2.0*np.pi step = (xmax-xmin)/(N) x...
1
2016-10-07T14:52:18Z
[ "python", "fft", "derivative" ]
Converting time data into a value for an array
39,710,229
<p>I'm writing a basic simulation for an astronomy application. I have a .csv file which is a list of observations. It has 11 columns where columns 2, 3, 4, 5, are decimal hour, day, month, year respectfully. The rest are names, coordinates etc. Each night, a selection of objects are observed once per night.</p> <p>Ea...
0
2016-09-26T18:49:41Z
39,710,415
<p>Consider using the standard <code>datetime</code> module: <a href="https://docs.python.org/3.5/library/datetime.html" rel="nofollow">https://docs.python.org/3.5/library/datetime.html</a></p> <pre><code>from datetime import datetime hourminute = .25 day = 1 month = 1 year = 2015 datetime(year, month, day, int(hourmi...
2
2016-09-26T19:02:23Z
[ "python", "date", "csv", "datetime" ]
How to separate time ranges/intervals into bins if intervals occur over multiple bins
39,710,296
<p>I have a dataset which consists of pairs of start-end times (say seconds) of something happening across a recorded period of time. For example:</p> <pre><code>#each tuple includes (start, stop) of the event happening data = [(0, 1), (5,8), (14,21), (29,30)] </code></pre> <p>I want to quantify what percentage of th...
1
2016-09-26T18:54:04Z
39,727,994
<p>If you don't mind using <code>numpy</code>, here is a strategy:</p> <pre><code>import numpy as np def bin_times(data, bin_size, total_length): times = np.zeros(total_length, dtype=np.bool) for start, stop in data: times[start:stop] = True binned = 100 * np.average(times.reshape(-1, bin_size), a...
1
2016-09-27T14:59:18Z
[ "python" ]
Get values from a text file using Python
39,710,345
<p>I have some data in text file organized like this:</p> <pre><code>26.11.2014 154601 26 53.07 16.12.2014 155001 25.2 52.1 </code></pre> <p>Where first column is date, second kilometers, third fuel in litre and last is cost in polish zloty. I am trying create my personal program with refuelling statistic...
-2
2016-09-26T18:58:16Z
39,710,770
<p>The following approach should help to get you started to get the data back from your text file. It first reads each line of your <code>benzyna.txt</code> file, removes the trailing newline and splits it based on <code>\t</code>. This creates a <code>data</code> list containing 2 rows with 4 strings in each. Next it ...
0
2016-09-26T19:23:57Z
[ "python", "text-files" ]
How to convert unicode numbers to ints?
39,710,365
<blockquote> <p>Arabic and Chinese have their own glyphs for digits. <code>int</code> works correctly with all the different ways to write numbers.</p> </blockquote> <p>I was not able to reproduce the behaviour (python 3.5.0)</p> <pre><code>&gt;&gt;&gt; from unicodedata import name &gt;&gt;&gt; name('𐹤') 'RUM...
5
2016-09-26T18:59:25Z
39,710,479
<p>Here's a way to convert to numerical values (casting to <code>int</code> does not work in all cases, unless there's a secret setting somewhere)</p> <pre><code>from unicodedata import numeric print(numeric('五')) </code></pre> <p>result: 5.0</p> <p>Someone noted (and was right) that some arabic or other chars wor...
5
2016-09-26T19:05:55Z
[ "python", "python-3.x", "unicode" ]
How to convert unicode numbers to ints?
39,710,365
<blockquote> <p>Arabic and Chinese have their own glyphs for digits. <code>int</code> works correctly with all the different ways to write numbers.</p> </blockquote> <p>I was not able to reproduce the behaviour (python 3.5.0)</p> <pre><code>&gt;&gt;&gt; from unicodedata import name &gt;&gt;&gt; name('𐹤') 'RUM...
5
2016-09-26T18:59:25Z
39,710,531
<p>The source is incorrect.</p> <p>From python doc:</p> <blockquote> <p>class int(x, base=10)</p> <p>Return an integer object constructed from a number or string x, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.</p> ...
-1
2016-09-26T19:08:57Z
[ "python", "python-3.x", "unicode" ]
How to convert unicode numbers to ints?
39,710,365
<blockquote> <p>Arabic and Chinese have their own glyphs for digits. <code>int</code> works correctly with all the different ways to write numbers.</p> </blockquote> <p>I was not able to reproduce the behaviour (python 3.5.0)</p> <pre><code>&gt;&gt;&gt; from unicodedata import name &gt;&gt;&gt; name('𐹤') 'RUM...
5
2016-09-26T18:59:25Z
39,710,800
<p><code>int</code> does not accept all ways to write numbers. It understands digit characters used for positional numeral systems, but neither <a href="http://std.dkuug.dk/jtc1/sc2/wg2/docs/n3087-1.pdf" rel="nofollow">Rumi</a> nor <a href="https://en.wikipedia.org/wiki/Chinese_numerals#Characters_used_to_represent_num...
5
2016-09-26T19:25:29Z
[ "python", "python-3.x", "unicode" ]