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
Using slices in Python
39,211,339
<p>I use the dataset from UCI repo: <a href="http://archive.ics.uci.edu/ml/datasets/Energy+efficiency" rel="nofollow">http://archive.ics.uci.edu/ml/datasets/Energy+efficiency</a> Then doing next:</p> <pre><code>from pandas import * from sklearn.neighbors import KNeighborsRegressor from sklearn.linear_model import Line...
0
2016-08-29T16:55:14Z
39,234,260
<p>I think that I had a similar problem before! Try to convert your data to numpy arrays before feeding them to <code>sklearn</code> estimators. It most probably solve the hashing problem. For instance, You can do:</p> <pre><code>Xtrn_array = Xtrn.as_matrix() Ytrn_array = Ytrn.as_matrix() </code></pre> <p>and use Xt...
1
2016-08-30T18:04:29Z
[ "python", "pandas", "scikit-learn", "slice", "prediction" ]
Boto3 get contents of S3 bucket
39,211,453
<p>I am trying to get the list of files in a subfolder of a bucket. Everything works fine, except, when I try to parse the files I notice that the first key my code pulls is the subfolder name. Is there any way to leave out the subfolder name as a key?</p> <pre><code>s3 = session.resource('s3') bucket = s3.Bucket('b...
1
2016-08-29T17:01:40Z
39,211,704
<p>I'd imagine there is a <code>.exclude</code> on the collections like in django but i couldn't see it as an option. You could try something like this</p> <pre><code>s3 = session.resource('s3') bucket = s3.Bucket('bucket_name') prefix = "sub1/" data = [obj for obj in list(bucket.objects.filter(Prefix=prefix)) if obj....
2
2016-08-29T17:16:48Z
[ "python", "amazon-s3", "boto3" ]
Scrapy spider does not store state (persistent state)
39,211,490
<p>Hi have a basic spider that runs to fetch all links on a given domain. I want to make sure it persists its state so that it can resume from where it left. I have followed the given url <a href="http://doc.scrapy.org/en/latest/topics/jobs.html" rel="nofollow">http://doc.scrapy.org/en/latest/topics/jobs.html</a> .But ...
2
2016-08-29T17:04:06Z
39,221,381
<p>The reason this was happening was due to the spider process being killed abruptly.</p> <p>The spider was not shutting down properly when I hit the Ctrl+C. Now, when the crawler shuts down properly the first time, it resumes properly too.</p> <p>So basically, make sure that you see the crawler ends/shuts down prope...
2
2016-08-30T07:30:25Z
[ "python", "scrapy" ]
Is there some way to make sure that the raw_input is only non-numeric?
39,211,531
<p>I want to make sure that the user enters the input in the correct format and i do know how to make sure its numeric input but i dont understand how to make sure its not numeric input.</p> <pre><code>x = raw_input('What is your name? ') y = raw_input('What is your age? ') try: something_to_make_sure_its_not_nume...
-2
2016-08-29T17:06:45Z
39,211,571
<p>There is also <code>isdigit()</code> function with <code>string</code> to check whether string is numeric or not. To check whether it is non-numeric, simply use <code>not</code> with the condition</p> <pre><code>&gt;&gt;&gt; 'xyx'.isdigit() False &gt;&gt;&gt; '123'.isdigit() True # Now check output with "not" &gt;...
1
2016-08-29T17:09:11Z
[ "python", "python-2.7" ]
Is there some way to make sure that the raw_input is only non-numeric?
39,211,531
<p>I want to make sure that the user enters the input in the correct format and i do know how to make sure its numeric input but i dont understand how to make sure its not numeric input.</p> <pre><code>x = raw_input('What is your name? ') y = raw_input('What is your age? ') try: something_to_make_sure_its_not_nume...
-2
2016-08-29T17:06:45Z
39,211,658
<p>Check if its a digit, and take the not of it</p> <pre><code>if x.isdigit(): print_error else: </code></pre> <p>Or use </p> <pre><code>x.isnumeric() </code></pre>
0
2016-08-29T17:14:08Z
[ "python", "python-2.7" ]
Is there some way to make sure that the raw_input is only non-numeric?
39,211,531
<p>I want to make sure that the user enters the input in the correct format and i do know how to make sure its numeric input but i dont understand how to make sure its not numeric input.</p> <pre><code>x = raw_input('What is your name? ') y = raw_input('What is your age? ') try: something_to_make_sure_its_not_nume...
-2
2016-08-29T17:06:45Z
39,211,672
<p>You might use <a href="https://docs.python.org/3/library/re.html?highlight=single%20line%20mode#re.VERBOSE" rel="nofollow">re module</a>, this allow you to check if a string contain for example a digit:</p> <pre><code>import re string = "626dsqd" test = re.search("\d", string) if test: print('please enter input i...
0
2016-08-29T17:14:52Z
[ "python", "python-2.7" ]
Is there some way to make sure that the raw_input is only non-numeric?
39,211,531
<p>I want to make sure that the user enters the input in the correct format and i do know how to make sure its numeric input but i dont understand how to make sure its not numeric input.</p> <pre><code>x = raw_input('What is your name? ') y = raw_input('What is your age? ') try: something_to_make_sure_its_not_nume...
-2
2016-08-29T17:06:45Z
39,211,674
<p>The following expression return <code>True</code> only of all the letters are non-digits:</p> <pre><code>all(not s.isdigit() for s in x) </code></pre>
0
2016-08-29T17:14:58Z
[ "python", "python-2.7" ]
Is there some way to make sure that the raw_input is only non-numeric?
39,211,531
<p>I want to make sure that the user enters the input in the correct format and i do know how to make sure its numeric input but i dont understand how to make sure its not numeric input.</p> <pre><code>x = raw_input('What is your name? ') y = raw_input('What is your age? ') try: something_to_make_sure_its_not_nume...
-2
2016-08-29T17:06:45Z
39,212,065
<p>You can use Regular Expressions to do that:</p> <pre><code>import re tester = re.match(r'^[a-zA-Z]*$', x) if tester: print x else: print 'Incorrect input' </code></pre> <p>If the return of the match method is <code>None</code> then your input does not satisfy your Regular Expression rule. In the example ab...
0
2016-08-29T17:39:47Z
[ "python", "python-2.7" ]
Bug in TensorFlow reduce_max for negative infinity?
39,211,546
<p>Using <code>tf.maximum</code> with negative inf inputs as follows:</p> <pre><code>tf.maximum(-math.inf, -math.inf).eval() </code></pre> <p>gives the expected result <code>-inf</code></p> <p>However, <code>tf.reduce_max</code>, on the same inputs:</p> <pre><code>tf.reduce_max([-math.inf, -math.inf]).eval() </code...
4
2016-08-29T17:07:41Z
39,358,214
<p>This turned out to be a bug in Eigen which has already been fixed and pushed out to TensorFlow.</p> <p>The issue can be tracked here: <a href="https://github.com/tensorflow/tensorflow/issues/4131" rel="nofollow">https://github.com/tensorflow/tensorflow/issues/4131</a></p>
0
2016-09-06T21:37:24Z
[ "python", "tensorflow" ]
mailgun sent attachments are 1kb blank images
39,211,606
<p>I have a very simple django based server i wish to use as an email sending server with mailgun</p> <p>I've managed to create a server endpoint that trigger an email with an attachment, this seems to work fine but when checking out the received email the attachment jpg file is just a 1kb blank image, im not sure if ...
2
2016-08-29T17:11:03Z
39,215,148
<p>As an answer instead of in comments - you're reading your files in text mode, not binary mode. That'll introduce odd line endings or otherwise mangle your files before you submit them to MailGun's API. You want to read your files in binary mode like so:</p> <pre><code>open('path/to/file', 'rb') </code></pre>
1
2016-08-29T21:01:39Z
[ "python", "django", "mailgun" ]
Is str.replace() or combining two slices a better way to remove a character?
39,211,615
<p>I am using CodingBat for practice exercises for the Python Language, I got to the "Warmup-1 > missing_char" exercise. The problem is as so:</p> <blockquote> <p>Given a non-empty string and an int n, return a new string where the char at index n has been removed. The value of n will be a valid index of a char ...
1
2016-08-29T17:11:37Z
39,212,031
<p>For the sake of posting a formal answer and as all previous comments suggest:</p> <p><code>str.replace(char,"")</code> will remove all occurences of the character regardless of their position. <code>str[:n]+str[n+1:]</code> will only remove the n-th character.</p> <p>So for that exercice <code>str.replace(char,"...
1
2016-08-29T17:37:58Z
[ "python" ]
Matplotlib xticks font size if string
39,211,707
<p>I am trying to change the font size of my x axis that happens to be strings and not numbers. I have changed other charts that have integers by using :</p> <pre><code>plt.xticks(size=10) </code></pre> <p>However, this dose not work for some of my graphs that have months in the place of integers. Keep in mind i am n...
1
2016-08-29T17:16:56Z
39,212,381
<p>Try setting the fontsize either by using the the <code>fontsize</code> keyword argument or if you want to globally change it to every plot in your script by updating the <code>rcParams</code> as</p> <pre><code>import matplotlib matplotlib.rc('xtick', labelsize=20) </code></pre> <p>Also look at this answer: <a hre...
1
2016-08-29T18:00:51Z
[ "python", "matplotlib" ]
Python 3 - A simple text string from user input to hex
39,211,716
<p>I want my code to accept user input then convert it to Hex</p> <pre><code>hex_name = input("Would you like to convert to hex?,Type Yes or No: ") if hex_name == 'Yes' or hex_name == 'yes' or hex_name == 'YES': hex_input = input("Enter String value here:") h_input = binascii.hexlify(b'hex_input') ...
1
2016-08-29T17:17:13Z
39,211,766
<p>Remove the quotes around <code>hex_input</code>:</p> <pre><code>binascii.hexlify(bytes(hex_input)) </code></pre>
0
2016-08-29T17:21:31Z
[ "python", "python-3.3" ]
Python 3 - A simple text string from user input to hex
39,211,716
<p>I want my code to accept user input then convert it to Hex</p> <pre><code>hex_name = input("Would you like to convert to hex?,Type Yes or No: ") if hex_name == 'Yes' or hex_name == 'yes' or hex_name == 'YES': hex_input = input("Enter String value here:") h_input = binascii.hexlify(b'hex_input') ...
1
2016-08-29T17:17:13Z
39,211,771
<p>You're specifically passing the string "hex_input", not the variable hex_input. That's why it's giving you the hex value of the string "hex_input".</p> <p>You have to remove the quotes around "hex_input":</p> <pre><code>if hex_name == 'Yes' or hex_name == 'yes' or hex_name == 'YES': hex_input = input("Ente...
0
2016-08-29T17:21:54Z
[ "python", "python-3.3" ]
Python 3 - A simple text string from user input to hex
39,211,716
<p>I want my code to accept user input then convert it to Hex</p> <pre><code>hex_name = input("Would you like to convert to hex?,Type Yes or No: ") if hex_name == 'Yes' or hex_name == 'yes' or hex_name == 'YES': hex_input = input("Enter String value here:") h_input = binascii.hexlify(b'hex_input') ...
1
2016-08-29T17:17:13Z
39,212,314
<p>Just remove the quotes around hex_input and you're good to go.</p> <p>Since you're pretty new to python, be aware that you can easily improve the quality and readability of your code. Following is just the start of it !</p> <pre><code>hex_name = input("Would you like to convert to hex?,Type Yes or No: ") hex_name ...
0
2016-08-29T17:56:29Z
[ "python", "python-3.3" ]
Python Pyplot won't plot surface fully
39,211,765
<p>In the attached picture you can see two plots of the same data. The left one is plotted with <code>plot_wireframe()</code> the right one with <code>plot_surface()</code></p> <p>Like this:</p> <pre><code>fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.plot_surface(xm, ym, Values) fig2 = plt.figure...
2
2016-08-29T17:21:22Z
39,219,458
<p>Given what the discussion in the comments, I <em>think</em> what's going on is you have a normal wireframe that looks as it should, but the surface plot is a 2D projection in that 3D axes object. I noticed that you are missing a line that shows up in <a href="http://matplotlib.org/examples/mplot3d/surface3d_demo.htm...
0
2016-08-30T05:37:23Z
[ "python", "matplotlib" ]
Creating more rows based on condition in pandas
39,211,772
<p>I have a dataframe like following:</p> <pre><code>id, index, val_1, val_2 1, 1, 0.2, 0 1, 2, 0.4, 0.2 2,2, 0.1, 0.5 2,4, 0.7, 0.0 .... </code></pre> <p>and so on</p> <p>Now, the complete range of index values that are allowed for each id is </p> <pre><code>[1,2,3,4] </code></pre> <p>So, if any of this index is ...
3
2016-08-29T17:22:03Z
39,211,924
<p>try this:</p> <pre><code>In [210]: from itertools import product In [211]: x = pd.DataFrame(list(product(df.id.unique(), [1,2,3,4])), columns=['id','index']).assign(val_1=0, val_2=0).set_index(['id','index']) In [212]: x.update(df.set_index(['id','index'])) In [213]: x Out[213]: val_1 val_2 id index 1...
4
2016-08-29T17:31:22Z
[ "python", "pandas", "dataframe" ]
Creating more rows based on condition in pandas
39,211,772
<p>I have a dataframe like following:</p> <pre><code>id, index, val_1, val_2 1, 1, 0.2, 0 1, 2, 0.4, 0.2 2,2, 0.1, 0.5 2,4, 0.7, 0.0 .... </code></pre> <p>and so on</p> <p>Now, the complete range of index values that are allowed for each id is </p> <pre><code>[1,2,3,4] </code></pre> <p>So, if any of this index is ...
3
2016-08-29T17:22:03Z
39,212,919
<p>Try this:</p> <p>Starting with this a df: </p> <pre><code>id index val_1 val_2 0 1 1 0.2 0.0 1 1 2 0.4 0.2 2 2 2 0.1 0.5 3 2 4 0.7 0.0 </code></pre> <p>Build New DataFrame:</p> <pre><code>df2 = pd.DataFrame({'id': np.repeat(df.id.unique(),4),'index': np.asar...
-1
2016-08-29T18:35:43Z
[ "python", "pandas", "dataframe" ]
Django: simple model for storing messages/notifications to/from users
39,211,784
<p>I am trying to create a simple Notification/Message model for my Django app. This will store notifications from the site to the user, and messages from one user to another. A working model I had been using looks like this:</p> <pre><code>class Notification(models.Model): sender = models.ForeignKey(User, on_dele...
2
2016-08-29T17:22:46Z
39,211,882
<p>My solution is to create a ReadFlag model.</p> <pre><code>class ReadFlag(models.Model): user = models.ForeignKey(User) message = models.ForeignKey(Message) created = ... </code></pre>
1
2016-08-29T17:28:55Z
[ "python", "django", "django-models" ]
Using pre-trained word embeddings in tensorflow's seq2seq function
39,211,791
<p>I am building a seq2seq model using functions in tensorflow's <code>seq2seq.py</code>, where they have a function like this:</p> <pre><code>embedding_rnn_seq2seq(encoder_inputs, decoder_inputs, cell, num_encoder_symbols, num_decoder_symbols, embedding_size, output...
1
2016-08-29T17:22:59Z
39,212,608
<p>There is no parameter you just hand over. Read in your embeddings (make sure vocabulary IDs match). Then, once you initialized all variables, find the embedding tensor (iterate through tf.all_variables to find the name). Then use tf.assign to overwrite the randomly initialized embeddings there with your embeddings.<...
1
2016-08-29T18:17:09Z
[ "python", "machine-learning", "tensorflow", "recurrent-neural-network", "lstm" ]
Tkinter - Preload window?
39,211,867
<p>I started building a python tkinter gui, the problem is, after adding many features to the gui, the loading started looking <strong>really ugly</strong>. When starting the mainloop, a blank window shows up for a few miniseconds before the widgets are loaded, the same happens with the other Toplevel windows ( except ...
3
2016-08-29T17:27:52Z
39,211,981
<p>The short answer is yes. You can set the window to appear as though you can't see it. Perform any code that takes time, and then display the window.</p> <p>Here's how:</p> <pre><code>class MyTkRoot(tk.Tk): def __init__(self): tk.Tk.__init__(self) self.attributes('-alpha', 0.0) # make window tr...
1
2016-08-29T17:34:34Z
[ "python", "user-interface", "tkinter", "lag" ]
Tkinter - Preload window?
39,211,867
<p>I started building a python tkinter gui, the problem is, after adding many features to the gui, the loading started looking <strong>really ugly</strong>. When starting the mainloop, a blank window shows up for a few miniseconds before the widgets are loaded, the same happens with the other Toplevel windows ( except ...
3
2016-08-29T17:27:52Z
39,212,770
<p>On your operating system tkinter seems to show the base <code>Tk</code> window before loading it's widgets causing that few milliseconds of blank window. To make it appear with all the widgets already loaded you will need to hide the window when starting and <code>.after</code> it has loaded show it again.</p> <p>...
2
2016-08-29T18:27:18Z
[ "python", "user-interface", "tkinter", "lag" ]
Tkinter - Preload window?
39,211,867
<p>I started building a python tkinter gui, the problem is, after adding many features to the gui, the loading started looking <strong>really ugly</strong>. When starting the mainloop, a blank window shows up for a few miniseconds before the widgets are loaded, the same happens with the other Toplevel windows ( except ...
3
2016-08-29T17:27:52Z
39,259,348
<p>After looking at your the project in your repository, I revised the code and dumped it all into one file. The following is the results from refactoring your modules and files into a fully self-contained program. The one thing that it is missing is the <code>Resource</code> class that handles all of the external depe...
1
2016-08-31T21:33:04Z
[ "python", "user-interface", "tkinter", "lag" ]
Winerror 3: File not found using ac2git
39,211,875
<p>I was using the ac2git tool to concert my accurev depot to git repository. I am getting the following error when running the command <strong>python ac2git.py</strong> after following the necessary steps, as instructed <a href="https://github.com/NavicoOS/ac2git/blob/master/how_it_works.md" rel="nofollow">here</a>.</...
1
2016-08-29T17:28:27Z
39,228,780
<p>I am not familiar with the tool you are using but it seems the last line in the output excerpt you provided gives the best information:</p> <pre><code>FileNotFoundError: [WinError 3] The system cannot find the path specified:'C:///Users/*****/*****/app/node_modules/bower/node_modules/update-notifier/node_modules/la...
1
2016-08-30T13:24:59Z
[ "python", "git", "accurev" ]
How can calculate the real distance between two points with GeoDjango?
39,211,879
<pre><code>from django.contrib.gis.geos import Point p1 = Point(36.74851779201058, -6.429006806692149, srid=4326) p2 = Point(37.03254161520977, -8.98366068931684, srid=4326) p1.distance(p2) Out: 2.5703941316759376 </code></pre> <p>But what is the unit of this float number?</p> <p>If you calculate this distance, this...
3
2016-08-29T17:28:44Z
39,259,317
<p>There's a solution to this online, which explains both what GeoDjango is doing originally (a distance calculation that doesn't use any standard units, essentially), but also, how to get it into a form that returns the distance in more useful units -- the code is very similar to what you're already doing, except that...
1
2016-08-31T21:30:56Z
[ "python", "django", "gis", "geodjango" ]
How can calculate the real distance between two points with GeoDjango?
39,211,879
<pre><code>from django.contrib.gis.geos import Point p1 = Point(36.74851779201058, -6.429006806692149, srid=4326) p2 = Point(37.03254161520977, -8.98366068931684, srid=4326) p1.distance(p2) Out: 2.5703941316759376 </code></pre> <p>But what is the unit of this float number?</p> <p>If you calculate this distance, this...
3
2016-08-29T17:28:44Z
39,302,364
<p>As far as I know, GeoDjango doesn't support calculating the real distance. It just calculates the distance geometrically. Therefore, I think you should use geopy as I did in my project..</p> <pre><code>from geopy.distance import vincenty distance = vincenty((lat1, lon1), (lat2, lon2)).kilometers </code></pre> <p>...
1
2016-09-03T01:04:10Z
[ "python", "django", "gis", "geodjango" ]
How can calculate the real distance between two points with GeoDjango?
39,211,879
<pre><code>from django.contrib.gis.geos import Point p1 = Point(36.74851779201058, -6.429006806692149, srid=4326) p2 = Point(37.03254161520977, -8.98366068931684, srid=4326) p1.distance(p2) Out: 2.5703941316759376 </code></pre> <p>But what is the unit of this float number?</p> <p>If you calculate this distance, this...
3
2016-08-29T17:28:44Z
39,304,823
<p>GeoDjango returns the Cartesian distance between points as a float value in degrees. To get the value of Distance in km or miles you can do the following: </p> <pre><code> dist = p1.distance(p2) dist.km # or dist.mi for miles </code></pre> <p>source: <a href="https://docs.djangoproject.com/en/1.10/ref/c...
-1
2016-09-03T08:22:21Z
[ "python", "django", "gis", "geodjango" ]
How can calculate the real distance between two points with GeoDjango?
39,211,879
<pre><code>from django.contrib.gis.geos import Point p1 = Point(36.74851779201058, -6.429006806692149, srid=4326) p2 = Point(37.03254161520977, -8.98366068931684, srid=4326) p1.distance(p2) Out: 2.5703941316759376 </code></pre> <p>But what is the unit of this float number?</p> <p>If you calculate this distance, this...
3
2016-08-29T17:28:44Z
39,314,643
<p>Usually, all spatial calculations yield results in the same coordinate system as the input was given. In your case you should seek a calculation using the <em>SRID 4326</em> which is longitude/latitude polars in degrees from the prime meridian and equator.</p> <p>Consequently, GeoDjango's distance calculation - if ...
2
2016-09-04T07:39:47Z
[ "python", "django", "gis", "geodjango" ]
Python regular expression returns nothing for match
39,211,916
<p>I am learning web scrapping using Python. I am trying to extract all links from one of popular financial site's site map.</p> <pre><code>bsObj = BeautifulSoup(html, "html.parser") for link in bsObj.findAll("a", href=re.compile("^(/india/stockmarket/pricechartquote/)*$")): if 'href' in link.attrs: pri...
-1
2016-08-29T17:30:50Z
39,211,963
<p>Have you tried checking if this regex matches the provided part of a url - it does not:</p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; &gt;&gt;&gt; pattern = re.compile("^(/india/stockmarket/pricechartquote/)*$") &gt;&gt;&gt; pattern.search("/india/stockmarket/pricechartquote/A") &gt;&gt;&gt; </code></pre> <p>...
2
2016-08-29T17:33:51Z
[ "python", "regex", "beautifulsoup" ]
Error Inserting data to mysql server through mysqldb in python
39,211,973
<p>MYsqldb is returning 1L when executing this:-</p> <pre><code>db=MySQLdb.connect('localhost','root','12345678','kitkat') cur=db.cursor() cur.execute("INSERT INTO justdial(id,email_raw,status) VALUES (NULL,'none','none')") </code></pre>
-2
2016-08-29T17:34:16Z
39,214,197
<p>If you are getting no errors Try adding db.commit after your execute</p> <p>I personally prefer mysql.connector.</p>
0
2016-08-29T19:58:00Z
[ "python", "sql", "mysql-python" ]
how to run jupyter notebook from 5th cell to 100th cell, without running other part of the notebook?
39,212,117
<p>Say I have a jupyter nootebook with 200 cells.</p> <p>how to run from 5th cell to 100th cell, without running other part of the notebook?</p> <p>Now I commend out 101th-200th and 1st-4th cell. I'm sure it is not the best practise.</p>
0
2016-08-29T17:43:45Z
39,217,231
<p>One cannot just run cells 5 thru 100 easily with the Jupyter notebook but there are a few options. The first is just selecting each cell and running <em>Merge Cell Above</em> from the edit menu then just running the new cell. The second, and best way I've found to do this is:</p> <ol> <li>First select the top cells...
1
2016-08-30T00:42:42Z
[ "python", "jupyter" ]
python only writes last output to file
39,212,267
<p>I am trying to write a program that picks a random musical scale until all have been chosen, and the problem I have is that my code is only writing one line to my text file. </p> <p>I know this is a similar question to <a href="http://stackoverflow.com/questions/19419751/python-only-writes-last-line-of-output">Pyth...
1
2016-08-29T17:54:01Z
39,212,485
<p>The code writes and overwrites at the same place in the output file. This is due to:</p> <pre><code>checker.seek(chars) checker.write(Scale + '\n') </code></pre> <p><code>chars</code> is set once and is never updated</p>
1
2016-08-29T18:07:21Z
[ "python", "list", "file", "append", "seek" ]
capture all matches in regex (g modifier not working for me)
39,212,327
<p>If I want to capture all of the last term in each product in this pattern:</p> <pre><code>PatternAnchor: Product-Computer-Keyboard, Product-Computer-Monitor, Product-Computer-Motherboard PatternEnd: </code></pre> <p>I tried this:</p> <pre><code>PatternAnchor: Product-(.*?)-(?P&lt;Item&gt;.*?)(,|PatternEnd:) </co...
1
2016-08-29T17:57:26Z
39,212,486
<p>If you want to match multiple strings starting with <code>Product-</code> with <code>PatternAnchor:</code> at start then you can use this PCRE regex with <code>\G</code></p> <pre><code>(?:PatternAnchor: |\G\h*,\h*)Product-([^-]*)-(?P&lt;Item&gt;[^,\h]*)(?=,|\h*PatternEnd:) </code></pre> <p><a href="https://regex10...
0
2016-08-29T18:07:27Z
[ "python", "regex" ]
capture all matches in regex (g modifier not working for me)
39,212,327
<p>If I want to capture all of the last term in each product in this pattern:</p> <pre><code>PatternAnchor: Product-Computer-Keyboard, Product-Computer-Monitor, Product-Computer-Motherboard PatternEnd: </code></pre> <p>I tried this:</p> <pre><code>PatternAnchor: Product-(.*?)-(?P&lt;Item&gt;.*?)(,|PatternEnd:) </co...
1
2016-08-29T17:57:26Z
39,213,131
<p>In Python, you may just use a 2 step approach:</p> <ul> <li>Check if the <code>PatternAnchor:</code> is present at the start of the string (note: this step might also be done with a regex in case of a more complex string)</li> <li>If yes, find all the patterns you need with a shorter <code>r'\bProduct-(.*?)-(?P&lt;...
0
2016-08-29T18:48:06Z
[ "python", "regex" ]
capture all matches in regex (g modifier not working for me)
39,212,327
<p>If I want to capture all of the last term in each product in this pattern:</p> <pre><code>PatternAnchor: Product-Computer-Keyboard, Product-Computer-Monitor, Product-Computer-Motherboard PatternEnd: </code></pre> <p>I tried this:</p> <pre><code>PatternAnchor: Product-(.*?)-(?P&lt;Item&gt;.*?)(,|PatternEnd:) </co...
1
2016-08-29T17:57:26Z
39,241,253
<p>Is this what you want? </p> <p><a href="https://regex101.com/r/mM1cV0/2" rel="nofollow">https://regex101.com/r/mM1cV0/2</a></p> <p>Your description and code/example feels very different to each other.</p>
0
2016-08-31T05:14:52Z
[ "python", "regex" ]
pandas drop rows with duplicates in some columns relative to other columns
39,212,332
<p>consider the dataframe <code>df</code></p> <pre><code>data = [ ['a', 'b', 'c', 'd'], ['a', 'b', 'e', 'f'], ['g', 'h', 'i', 'j'], ['k', 'l', 'm', 'n'], ['m', 'n', 'o', 'p'], ['q', 'r', 's', 't'], ['u', 'v', 'w', 'x'], ['y', 'z', 'q', 'r'], ] cols = pd.MultiIndex.from_product([list('A...
3
2016-08-29T17:57:38Z
39,212,476
<p>try this:</p> <pre><code>In [248]: df[~(df.A.isin(df.B.to_dict('list')).all(1) | df.B.isin(df.A.to_dict('list')).all(1))] Out[248]: A B X Y X Y 0 a b c d 1 a b e f 2 g h i j 6 u v w x </code></pre> <p>Explanation:</p> <pre><code>In [249]: df.A.isin(df.B.to_dict('list')) Out[249]: ...
3
2016-08-29T18:06:59Z
[ "python", "pandas" ]
IF statement picking first option in currency converter (python)
39,212,354
<pre><code>print "Pound Sterling converter" print "You can convert pounds to either dollars, euros or yen" print dollar = 0 euro = 0 yen = 0 convert_to = input ("What currency do you want to convert to? ") amount = input("How much would you like to convert? ") print if convert_to == dollar: amount = amount * 1...
0
2016-08-29T17:59:07Z
39,212,532
<p>Please try to change to this:</p> <pre><code>if convert_to == "dollar": amount = float(amount) * 1.3 elif convert_to == "euro": amount = float(amount) * 1.17 elif convert_to == "yen": amount = float(amount) * 133.66 </code></pre> <p>There are 2 changes. First one is to set currencies (dollar , euro , ...
1
2016-08-29T18:10:41Z
[ "python", "if-statement" ]
IF statement picking first option in currency converter (python)
39,212,354
<pre><code>print "Pound Sterling converter" print "You can convert pounds to either dollars, euros or yen" print dollar = 0 euro = 0 yen = 0 convert_to = input ("What currency do you want to convert to? ") amount = input("How much would you like to convert? ") print if convert_to == dollar: amount = amount * 1...
0
2016-08-29T17:59:07Z
39,212,583
<p>Your code is not working because you're assuming that the <code>input()</code> function returns an integer. It does not. The <code>input()</code> function returns a string, so this:</p> <p><code>convert_to == dollars</code> </p> <p>is equal to: </p> <p><code>str == 1</code></p> <p>which will never be true. Just ...
0
2016-08-29T18:14:30Z
[ "python", "if-statement" ]
IF statement picking first option in currency converter (python)
39,212,354
<pre><code>print "Pound Sterling converter" print "You can convert pounds to either dollars, euros or yen" print dollar = 0 euro = 0 yen = 0 convert_to = input ("What currency do you want to convert to? ") amount = input("How much would you like to convert? ") print if convert_to == dollar: amount = amount * 1...
0
2016-08-29T17:59:07Z
39,212,588
<p>First of all dollar, euro and yen have the same start value (0).</p> <p>I think, you must put different values.</p> <pre><code>dollar = 0 euro = 1 yen = 2 </code></pre> <p>Then, you can show amount (print amount) but your calculate value is "amountpython".</p>
0
2016-08-29T18:14:46Z
[ "python", "if-statement" ]
IF statement picking first option in currency converter (python)
39,212,354
<pre><code>print "Pound Sterling converter" print "You can convert pounds to either dollars, euros or yen" print dollar = 0 euro = 0 yen = 0 convert_to = input ("What currency do you want to convert to? ") amount = input("How much would you like to convert? ") print if convert_to == dollar: amount = amount * 1...
0
2016-08-29T17:59:07Z
39,212,703
<p>If i understand correctly, the user will input either "0", "1" or "2" as a input, for the convertion for dollar, euro or yen respectively. So you need to change the initial values of dollar, euro and yen. Changing that, the version with integer input will work.</p> <pre><code>dollar = 0 euro = 1 yen = 2 </code></pr...
1
2016-08-29T18:23:32Z
[ "python", "if-statement" ]
IF statement picking first option in currency converter (python)
39,212,354
<pre><code>print "Pound Sterling converter" print "You can convert pounds to either dollars, euros or yen" print dollar = 0 euro = 0 yen = 0 convert_to = input ("What currency do you want to convert to? ") amount = input("How much would you like to convert? ") print if convert_to == dollar: amount = amount * 1...
0
2016-08-29T17:59:07Z
39,212,860
<p>In your case dollar, euro and yen , you have initialized to the same value that is zero. You should assign different values , for example;</p> <pre><code>dollar=0 euro=0 yen=0 </code></pre> <p>Then try this</p> <pre><code>print "Pound Sterling converter" print "You can convert pounds to either dollars, euros or y...
0
2016-08-29T18:32:03Z
[ "python", "if-statement" ]
Can't get Django to work on my Mac
39,212,384
<p>I'm having difficulty getting Django to work on my Mac. I pip installed it, as well as downloading it on PyCharm. I have a feeling it will work on PyCharm if I knew what I'm doing. I dont. haha. It's my first time. I am trying to work off the tutorial that they provide on their site. Here is where I run into trouble...
0
2016-08-29T18:01:11Z
39,213,408
<p>Seems to me that pip is not configured with the python that you are using. From the output you posted, pip is installing Django for the python executable residing in here:</p> <pre><code>/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages </code></pre> <p>what is the output of <code>ls -l...
0
2016-08-29T19:05:33Z
[ "python", "django", "osx", "terminal" ]
Can't get Django to work on my Mac
39,212,384
<p>I'm having difficulty getting Django to work on my Mac. I pip installed it, as well as downloading it on PyCharm. I have a feeling it will work on PyCharm if I knew what I'm doing. I dont. haha. It's my first time. I am trying to work off the tutorial that they provide on their site. Here is where I run into trouble...
0
2016-08-29T18:01:11Z
39,215,077
<p><strong>From Comments</strong></p> <p>Looks like a virtual environment problem. Without going into the extreme details of your environment settings, try the following: make and navigate to an empty directory, type <code>pyvenv-3.5 ./Env</code>, then <code>source ./Env/bin/activate</code>, next <code>pip install dja...
0
2016-08-29T20:56:40Z
[ "python", "django", "osx", "terminal" ]
How to check environment variables in python
39,212,491
<p>How to check all environment variables in python. I'm trying to install cx_Oracle and instant client and want to make sure all my variables are ok. </p>
-1
2016-08-29T18:07:51Z
39,212,652
<p>To elaborate further on my comment. All environment variables can be found within the <code>os.environ</code> dictionary (you'll need to <code>import os</code> first).</p> <p>It looks like <code>TNS_ADMIN</code> is one of the environment variables used for <code>tnsnames.ora</code>, so you can check like this:</p> ...
1
2016-08-29T18:19:42Z
[ "python", "oracle11g", "cx-oracle" ]
Django use URL tag in template from app specific urls?
39,212,519
<p>I have the following URLs in my project <code>urls.py</code></p> <pre><code>urlpatterns = i18n_patterns( url(r'^register/', include('register.urls')), ) </code></pre> <p>So I maintain urls in the register app, so the <code>urls.py</code> in my <code>register</code> app looks like this:</p> <pre><code>urlpatte...
0
2016-08-29T18:09:38Z
39,212,556
<p>Have you tried: <code>&lt;a href="{% url 'register:register_test' %}"/&gt;Test&lt;/a&gt;</code>? You might want to give the register urls a name space first though:</p> <p>urls.py</p> <pre><code>urlpatterns = i18n_patterns( url(r'^register/', include('register.urls', namespace='register'), ) </code></pre> <p...
1
2016-08-29T18:12:05Z
[ "python", "django", "url" ]
Django use URL tag in template from app specific urls?
39,212,519
<p>I have the following URLs in my project <code>urls.py</code></p> <pre><code>urlpatterns = i18n_patterns( url(r'^register/', include('register.urls')), ) </code></pre> <p>So I maintain urls in the register app, so the <code>urls.py</code> in my <code>register</code> app looks like this:</p> <pre><code>urlpatte...
0
2016-08-29T18:09:38Z
39,212,623
<p>project urls.py</p> <pre><code>urlpatterns = i18n_patterns( url(r'^register/', include('register.urls', namespace="register")), ) </code></pre> <p>app urls.py</p> <pre><code>urlpatterns = patterns( url(r'^test/$', views.Test, name="register_test"), ) </code></pre> <p>template.html</p> <pre><code>&lt;a h...
0
2016-08-29T18:17:48Z
[ "python", "django", "url" ]
Is there a way to create and name an object/class, as well as run a method of the class in the same line?
39,212,524
<p>I am just trying to clean up some code and I was wondering if there is a way to create a new named object as well as run a method in the objects class in the same line. For example:</p> <pre><code>self.equipment_widgets["NumOfStagesLabelCentComp"]=tk.Label(self.parent, text="Number of Stages:", bg="white") self.equ...
0
2016-08-29T18:10:14Z
39,212,701
<p>You need to design your class methods to be chainable, which means that all methods that just modify the object (as opposed to returning information from the object) should end with <code>return self</code>. This allows you to write:</p> <pre><code>object.method1(...).method2(...).method3(...) </code></pre> <p>If ...
1
2016-08-29T18:23:22Z
[ "python", "python-2.7", "tkinter" ]
Unable to pipe python output to program
39,212,541
<p>I want to pipe stdout from python to another program, but I am faceing a problem where my stdout is not piped.</p> <p>I have it shortened down to a simple sample:</p> <pre><code>import time while True: print("Hello!") time.sleep(1) </code></pre> <p>I check it with cat like so:</p> <pre><code>./my_python...
1
2016-08-29T18:11:20Z
39,212,574
<p>You'll need to flush the stdout:</p> <pre><code>import time import sys while True: print("Hello!") sys.stdout.flush() time.sleep(1) </code></pre>
4
2016-08-29T18:13:44Z
[ "python", "linux" ]
Querying postgresql for DateTime values between two dates
39,212,620
<p>I have the following dateTime text type variable in Postgres table</p> <pre><code>"2016-05-12T23:59:11+00:00" "2016-05-13T11:00:11+00:00" "2016-05-13T23:59:11+00:00" "2016-05-15T10:10:11+00:00" "2016-05-16T10:10:11+00:00" "2016-05-17T10:10:11+00:00" </code></pre> <p>I have to write a Python function to e...
0
2016-08-29T18:17:32Z
39,213,596
<p>I'm not familiar with postgresql, but you can convert the strings to the <code>struct_time</code> class which is part of the built in <a href="https://docs.python.org/3/library/time.html" rel="nofollow"><code>time</code> package</a> in Python and simply make comparisons between them.</p> <pre><code>import time tim...
0
2016-08-29T19:18:55Z
[ "python", "postgresql", "datetime", "pandas" ]
Querying postgresql for DateTime values between two dates
39,212,620
<p>I have the following dateTime text type variable in Postgres table</p> <pre><code>"2016-05-12T23:59:11+00:00" "2016-05-13T11:00:11+00:00" "2016-05-13T23:59:11+00:00" "2016-05-15T10:10:11+00:00" "2016-05-16T10:10:11+00:00" "2016-05-17T10:10:11+00:00" </code></pre> <p>I have to write a Python function to e...
0
2016-08-29T18:17:32Z
39,214,437
<p>When working with sql, you should always use your sql library to substitute parameters into the query, instead of using Python's string operators. This avoids the risk of malformed queries or sql injection attacks. See e.g., <a href="http://bugcharmer.blogspot.com/2013/03/basics-avoiding-sql-injection.html" rel="nof...
0
2016-08-29T20:13:36Z
[ "python", "postgresql", "datetime", "pandas" ]
Why print command gives a new line even though there is no data to print
39,212,632
<p>Just typing <code>print</code> only gives newline in python. Typing <code>print</code> without the brackets in 3.x will also gives a newline. Why?</p>
2
2016-08-29T18:18:24Z
39,212,664
<p>Because <a href="https://docs.python.org/3/library/functions.html#print">the documentation</a> says so</p> <blockquote> <p><code>print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)</code></p> <p>Print objects to the text stream file, separated by sep and followed by end. sep, end and file, if pr...
6
2016-08-29T18:20:42Z
[ "python", "python-2.7", "python-3.x" ]
Why print command gives a new line even though there is no data to print
39,212,632
<p>Just typing <code>print</code> only gives newline in python. Typing <code>print</code> without the brackets in 3.x will also gives a newline. Why?</p>
2
2016-08-29T18:18:24Z
39,212,669
<p>In Python 3, print is now a function. It will print a new line character at the end of your statement. </p> <p>If you don't specify an "end" it will by default use a new line character. </p> <p>You can prevent this by doing something such as:</p> <pre><code>print("hello world", end="") </code></pre>
1
2016-08-29T18:21:23Z
[ "python", "python-2.7", "python-3.x" ]
Why print command gives a new line even though there is no data to print
39,212,632
<p>Just typing <code>print</code> only gives newline in python. Typing <code>print</code> without the brackets in 3.x will also gives a newline. Why?</p>
2
2016-08-29T18:18:24Z
39,213,065
<p>It is interesting how languages differ in this. </p> <p><code>print</code> in the Korn shell (ksh) has the same behaviour as <code>python</code>, i.e. it adds a newline. Bash does not have a <code>print</code>, relying on <code>echo</code> instead, which also adds a newline (which, like python, can be suppressed)...
1
2016-08-29T18:43:25Z
[ "python", "python-2.7", "python-3.x" ]
Why print command gives a new line even though there is no data to print
39,212,632
<p>Just typing <code>print</code> only gives newline in python. Typing <code>print</code> without the brackets in 3.x will also gives a newline. Why?</p>
2
2016-08-29T18:18:24Z
39,213,600
<p>Because the default parameter in print is \n for the end, though if you pass parameter for print end variable as \t or space , then you can see the same ! </p> <p>But it works 2.7 and above!</p>
1
2016-08-29T19:19:17Z
[ "python", "python-2.7", "python-3.x" ]
How can I convert a list to named variables in Python?
39,212,783
<p>Is there a quick way in python to convert a list of values to named variables?</p> <p>For example:</p> <pre><code>row = ['files', 'file.pdf', 'D1234', 43] folder = row[0] name = row[1] doc_id = row[2] page_num = row[3] </code></pre>
0
2016-08-29T18:27:54Z
39,212,797
<p>You can use <a href="https://docs.python.org/3/tutorial/controlflow.html#unpacking-argument-lists">unpacking</a></p> <pre><code>folder, name, doc_id, page_num = row </code></pre>
5
2016-08-29T18:28:54Z
[ "python", "list" ]
How can I convert a list to named variables in Python?
39,212,783
<p>Is there a quick way in python to convert a list of values to named variables?</p> <p>For example:</p> <pre><code>row = ['files', 'file.pdf', 'D1234', 43] folder = row[0] name = row[1] doc_id = row[2] page_num = row[3] </code></pre>
0
2016-08-29T18:27:54Z
39,213,552
<p>You can use this below patterns to do it more professionally</p> <pre><code>v = ['files', 'file.pdf', 'D1234', 43] keys = ['folder', 'name', 'doc_id', 'page_num'] junk = map(lambda k, v: dict.update({k: v}), keys, values) </code></pre>
0
2016-08-29T19:15:52Z
[ "python", "list" ]
InvalidSchema("No connection adapters were found for '%s'" % url)
39,212,867
<p>I was able to gather data from a web page using this </p> <pre><code>import requests import lxml.html import re url = "http://animesora.com/flying-witch-episode-7-english-subtitle/" r = requests.get(url) page = r.content dom = lxml.html.fromstring(page) for link in dom.xpath('//div[@class="downloadarea"]//a/@href...
-1
2016-08-29T18:32:32Z
39,212,974
<p>You are passing in the <em>whole list</em>:</p> <pre><code>for link2 in down: r2 = requests.get(down) </code></pre> <p>Note how you passed in <code>down</code>, <em>not</em> <code>link2</code>. <code>down</code> is a list, not a single URL string.</p> <p>Pass in <code>link2</code>:</p> <pre><code>for link2 i...
0
2016-08-29T18:38:43Z
[ "python", "python-requests" ]
Change IP Address Python Selenium
39,212,888
<p>I Try run code with Python Selenium</p> <pre><code>from selenium import webdriver import time profile = webdriver.FirefoxProfile() profile.set_preference("network.proxy_type",1) profile.set_preference("network.proxy.http","124.240.187.80") profile.set_preference("network.proxy.http_port",82) profile.update_prefere...
0
2016-08-29T18:34:03Z
39,213,025
<p>Use desired capabilities for FF.</p> <pre><code>proxy = "124.240.187.80:82" webdriver.DesiredCapabilities.FIREFOX['proxy'] = { "httpProxy":proxy, "ftpProxy":proxy, "sslProxy":proxy, "noProxy":None, "proxyType":"MANUAL", "class":"org.openqa.selenium.Proxy", "autodetect":False } </code></pre> <...
0
2016-08-29T18:41:23Z
[ "python", "selenium", "proxy", "web-crawler" ]
UNAME_SYSNAME on Python3
39,212,894
<p>I'm having problems installing an extention on python3.5 on Windows.</p> <p>Traced it to a <code>IF UNAME_SYSNAME == u"Windows":</code> not being triggered. According to <a href="http://stackoverflow.com/questions/35887318/cannot-install-pylearn2-to-winpython-64bit-3-4-4-1/35970202#35970202">Cannot install pylearn2...
1
2016-08-29T18:34:48Z
39,232,480
<p>Looks like Cython doesn't really support python3.</p> <p>If it adds support feel free to replace this answer</p>
0
2016-08-30T16:16:28Z
[ "python", "windows", "python-3.x", "cython" ]
why does this code not work in real environment? saying 'normal' is undefined (new coder)
39,212,903
<p>my question: I can get this to work in codeskulptor but not any of my IDE. Please help!</p> <pre><code>Uinput = input("first morph") Uinput2 = input("second morph") #this section of code accepts normal or recessive to #calculate if you will get hets. If hets, clarify morph in separate function #input to compare ar...
0
2016-08-29T18:35:12Z
39,212,966
<p>It sounds like CodeSkulptor is running Python 3 and your IDEs are running Python 2. The <code>input</code> function behaves differently between the two Pythons.</p> <p>If you configure your IDEs to use Python 3, your code should work.</p> <p>Alternatively, the Python 2 <code>raw_input</code> function does what the...
0
2016-08-29T18:38:02Z
[ "python", "python-2.x" ]
Trying to split out a character from a bash "list"
39,212,923
<p>So I have this command that runs the following report in your shell; </p> <pre><code>Command output Available Reports for: isl-01-chi Time Zone: CDT ================================================================================ |ID |FSA Job Start |FSA Job End |Size | ====...
0
2016-08-29T18:36:00Z
39,212,984
<p>If the output is always sorted, then read each line into a list, get the second to last entry in the list, and discard the rest.</p>
0
2016-08-29T18:39:07Z
[ "python" ]
Trying to split out a character from a bash "list"
39,212,923
<p>So I have this command that runs the following report in your shell; </p> <pre><code>Command output Available Reports for: isl-01-chi Time Zone: CDT ================================================================================ |ID |FSA Job Start |FSA Job End |Size | ====...
0
2016-08-29T18:36:00Z
39,212,996
<p>how about</p> <p><code>largest_id = max(int(line.split()[0][1:]) for line in output.split("\n")[5::2])</code></p> <p>if the output is always sorted, then</p> <p><code>largest_id = int(output.split('\n')[-2].split()[0][1:])</code></p> <p>more educatively :</p> <pre><code>lines = output.split('\n') second_to_last...
2
2016-08-29T18:39:50Z
[ "python" ]
Trying to split out a character from a bash "list"
39,212,923
<p>So I have this command that runs the following report in your shell; </p> <pre><code>Command output Available Reports for: isl-01-chi Time Zone: CDT ================================================================================ |ID |FSA Job Start |FSA Job End |Size | ====...
0
2016-08-29T18:36:00Z
39,213,303
<p>I think that is better thake the value with shell. </p> <pre><code>your_command | grep -Eo '^\|[0-9]+'| cut -d "|" -f2 | sort | tail -n1 </code></pre>
0
2016-08-29T18:59:11Z
[ "python" ]
Trying to split out a character from a bash "list"
39,212,923
<p>So I have this command that runs the following report in your shell; </p> <pre><code>Command output Available Reports for: isl-01-chi Time Zone: CDT ================================================================================ |ID |FSA Job Start |FSA Job End |Size | ====...
0
2016-08-29T18:36:00Z
39,213,453
<hr> <h2> </h2> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>data="..." #// Load Your Shell output l=[] Output="" MaxID=0 for a in data.split("\n"): id=a.split()[...
-1
2016-08-29T19:08:12Z
[ "python" ]
Trying to split out a character from a bash "list"
39,212,923
<p>So I have this command that runs the following report in your shell; </p> <pre><code>Command output Available Reports for: isl-01-chi Time Zone: CDT ================================================================================ |ID |FSA Job Start |FSA Job End |Size | ====...
0
2016-08-29T18:36:00Z
39,213,493
<p>Also you can do it using sort command in shell.</p> <pre><code>your_command | awk '{print $1}' | sort | tail -n1 </code></pre>
-1
2016-08-29T19:11:13Z
[ "python" ]
Trying to split out a character from a bash "list"
39,212,923
<p>So I have this command that runs the following report in your shell; </p> <pre><code>Command output Available Reports for: isl-01-chi Time Zone: CDT ================================================================================ |ID |FSA Job Start |FSA Job End |Size | ====...
0
2016-08-29T18:36:00Z
39,213,739
<p>I'd use a regex because it looks like the ID is a 3 digit (or more) number preceded by the pipe (|) character.</p> <p>This should do it:</p> <pre><code>regex = re.compile(r'(?&lt;=\|)\d{,3}') m = regex.findall(text) max(m) </code></pre>
0
2016-08-29T19:27:55Z
[ "python" ]
django binary file download corrupted in browsers
39,212,965
<p>I have a view that after authentication/permissions serves a file as saved in a FileField.</p> <pre><code>from django.http import StreamingHttpResponse from rest_framework import viewsets from rest_framework.decorators import detail_route from wsgiref.util import FileWrapper import mimetypes from myapp.models impor...
3
2016-08-29T18:38:01Z
39,213,147
<p>This is typically caused while uploading files/data through FTP as ASCII file transfer type. The "ASCII transfer type" will transfer the files as regular text files and so no problem. but, the "Binary transfer type" will transfer the data in binary mode which handles the files as binary data instead of text data. ...
0
2016-08-29T18:49:11Z
[ "python", "django", "django-rest-framework" ]
django binary file download corrupted in browsers
39,212,965
<p>I have a view that after authentication/permissions serves a file as saved in a FileField.</p> <pre><code>from django.http import StreamingHttpResponse from rest_framework import viewsets from rest_framework.decorators import detail_route from wsgiref.util import FileWrapper import mimetypes from myapp.models impor...
3
2016-08-29T18:38:01Z
39,332,657
<p>The problem was solved when I used nginx + uwsgi. I think it has to do with some of the 'Hop-by-hop' headers that django's runserver refuses to add and errors out if I add them manually. Which are generally related to reverse proxies. </p>
1
2016-09-05T14:22:45Z
[ "python", "django", "django-rest-framework" ]
Scrapy export csv without specifying in cmd
39,213,095
<p>I understand how to export my scraped data in to a csv format via</p> <pre><code>scrapy crawl &lt;spider_name&gt; -o filename.csv </code></pre> <p>However I'd like to run my spider from a script and automatically write to csv (so I can use schedule to run the spider at particular times). How could I implement this...
0
2016-08-29T18:45:42Z
39,213,373
<p>Scrapy uses pipelines to post process the data you have scraped. You can create a file called <code>pipelines.py</code> which contains the following code which exports your data into a folder <code>exports</code>. Here's some code that I use in one of my pip projects</p> <pre><code>from scrapy import signals from s...
1
2016-08-29T19:03:15Z
[ "python", "python-2.7", "scrapy", "scrapy-spider" ]
Python 3 - Post comment on forum
39,213,526
<p>I have some python background experience. However I don't know how to post comment to forum.</p> <p>How can I get started? I read about urllib, but I still don't know how to post.</p> <p>Can you help me?</p> <p>What information do I need to extract?</p>
-1
2016-08-29T19:14:14Z
39,213,783
<p>Here are some tools that might help you:</p> <ul> <li>Browser developer tools is probably where you should begin. Try to record a POST request in the "network" pane and see what parameters your browser sends to the server.</li> <li>If you need to parse HTML to extract data, use <a href="https://www.crummy.com/softw...
0
2016-08-29T19:31:08Z
[ "python", "post", "comments" ]
Python Regular Expression; replacing a portion of match
39,213,585
<p>How would I limit match/replacement the leading zeros in e004_n07? However, if either term contains all zeros, then I need to retain one zero in the term (see example below). For the input string, there will always be 3 digits in the first value and 2 digits in the second value.</p> <p>Example input and output</p>...
1
2016-08-29T19:18:16Z
39,213,641
<p>There's no need to use <code>re.sub</code> if your replacement is so simple - simply use <a class='doc-link' href="http://stackoverflow.com/documentation/python/278/string-methods/1008/replace-all-occurrences-of-one-substring-with-another-substring#t=201608291922416212581"><code>str.replace</code></a>:</p> <pre><co...
1
2016-08-29T19:21:51Z
[ "python", "regex" ]
Python Regular Expression; replacing a portion of match
39,213,585
<p>How would I limit match/replacement the leading zeros in e004_n07? However, if either term contains all zeros, then I need to retain one zero in the term (see example below). For the input string, there will always be 3 digits in the first value and 2 digits in the second value.</p> <p>Example input and output</p>...
1
2016-08-29T19:18:16Z
39,213,817
<p>If you want to only remove zeros after letters, you may use:</p> <pre><code>([a-zA-Z])0+ </code></pre> <p>Replace with <code>\1</code> backreference. See the <a href="https://regex101.com/r/oI2vF0/1" rel="nofollow">regex demo</a>.</p> <p>The <code>([a-zA-Z])</code> will capture a letter and <code>0+</code> will m...
4
2016-08-29T19:33:09Z
[ "python", "regex" ]
Python Regular Expression; replacing a portion of match
39,213,585
<p>How would I limit match/replacement the leading zeros in e004_n07? However, if either term contains all zeros, then I need to retain one zero in the term (see example below). For the input string, there will always be 3 digits in the first value and 2 digits in the second value.</p> <p>Example input and output</p>...
1
2016-08-29T19:18:16Z
39,213,823
<p>If your requirement is that you MUST use <code>regex</code>, then below is your regex pattern:</p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; s = 'e004_n07' &gt;&gt;&gt; line = re.sub(r"0", "", s) &gt;&gt;&gt; line 'e4_n7' </code></pre> <p>However it is recommended not to use regex when there is other efficien...
0
2016-08-29T19:33:24Z
[ "python", "regex" ]
Python Regular Expression; replacing a portion of match
39,213,585
<p>How would I limit match/replacement the leading zeros in e004_n07? However, if either term contains all zeros, then I need to retain one zero in the term (see example below). For the input string, there will always be 3 digits in the first value and 2 digits in the second value.</p> <p>Example input and output</p>...
1
2016-08-29T19:18:16Z
39,213,914
<p><em><strong>edit:</strong> Don't let anybody talk you out of validating the format of the fixed data. If that's what you need, don't settle for something overly simple .</em> </p> <p>Not very pretty, but in a situation that seems fixed, you can just<br> set all the permutations, then blindly capture the good parts...
-1
2016-08-29T19:39:52Z
[ "python", "regex" ]
Convert text data from requests object to dataframe with pandas
39,213,597
<p>Using requests I am creating an object which is in .csv format. How can I then write that object to a DataFrame with pandas?</p> <p>To get the requests object in text format:</p> <pre><code>import requests import pandas as pd url = r'http://test.url' r = requests.get(url) r.text #this will return the data as tex...
1
2016-08-29T19:19:04Z
39,213,616
<p>I think you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow"><code>read_csv</code></a> with <code>url</code>:</p> <pre><code>pd.read_csv(url) </code></pre> <blockquote> <p><strong>filepath_or_buffer</strong> : str, pathlib.Path, py._path.local.LocalPath ...
1
2016-08-29T19:20:11Z
[ "python", "csv", "pandas", "dataframe", "python-requests" ]
Convert text data from requests object to dataframe with pandas
39,213,597
<p>Using requests I am creating an object which is in .csv format. How can I then write that object to a DataFrame with pandas?</p> <p>To get the requests object in text format:</p> <pre><code>import requests import pandas as pd url = r'http://test.url' r = requests.get(url) r.text #this will return the data as tex...
1
2016-08-29T19:19:04Z
39,213,730
<p>if the url has no authentication then you can directly use read_csv(url)</p> <p>if you have authentication you can use request to get it un-pickel and print the csv and make sure the result is CSV and use panda.</p> <p>You can directly use importing import csv</p>
1
2016-08-29T19:27:31Z
[ "python", "csv", "pandas", "dataframe", "python-requests" ]
Convert text data from requests object to dataframe with pandas
39,213,597
<p>Using requests I am creating an object which is in .csv format. How can I then write that object to a DataFrame with pandas?</p> <p>To get the requests object in text format:</p> <pre><code>import requests import pandas as pd url = r'http://test.url' r = requests.get(url) r.text #this will return the data as tex...
1
2016-08-29T19:19:04Z
39,213,780
<p>Try this</p> <pre><code>import requests import pandas as pd import io urlData = requests.get(url).content rawData = pd.read_csv(io.StringIO(urlData.decode('utf-8'))) </code></pre>
1
2016-08-29T19:30:35Z
[ "python", "csv", "pandas", "dataframe", "python-requests" ]
Apparently, Python Strings are not 'born equal'
39,213,688
<p>I'm trying to wrap my brain around the 'text encoding standards'. When interpreting a bunch of bytes as 'text', one has to know which 'encoding sheme' applies. Possible candidates that I know of:</p> <ul> <li>ASCII: Very basic encoding scheme, supports 128 characters.</li> <li>CP-1252: Windows encoding scheme for t...
4
2016-08-29T19:24:34Z
39,214,238
<p>CP-1252 is basically a byte for byte codec; it can decode arbitrary bytes, including the bytes from UTF-8 encoding. So effectively, assuming you're on Windows using a Western locale, where the default encoding provided to <code>open</code> is <code>cp-1252</code>, if you never work with the string in Python, just re...
3
2016-08-29T20:00:41Z
[ "python", "python-3.x", "unicode", "encoding", "utf-8" ]
Apparently, Python Strings are not 'born equal'
39,213,688
<p>I'm trying to wrap my brain around the 'text encoding standards'. When interpreting a bunch of bytes as 'text', one has to know which 'encoding sheme' applies. Possible candidates that I know of:</p> <ul> <li>ASCII: Very basic encoding scheme, supports 128 characters.</li> <li>CP-1252: Windows encoding scheme for t...
4
2016-08-29T19:24:34Z
39,214,252
<p>When no encoding is passed explicitly, <a href="https://docs.python.org/3.5/library/functions.html#open" rel="nofollow"><code>open()</code> uses the preferred system encoding</a> both for reading and for writing (not sure exactly how the preferred encoding is detected on Windows).</p> <p>So, when you write:</p> <p...
2
2016-08-29T20:02:19Z
[ "python", "python-3.x", "unicode", "encoding", "utf-8" ]
Apparently, Python Strings are not 'born equal'
39,213,688
<p>I'm trying to wrap my brain around the 'text encoding standards'. When interpreting a bunch of bytes as 'text', one has to know which 'encoding sheme' applies. Possible candidates that I know of:</p> <ul> <li>ASCII: Very basic encoding scheme, supports 128 characters.</li> <li>CP-1252: Windows encoding scheme for t...
4
2016-08-29T19:24:34Z
39,214,323
<p>To fully grasp the answer we need to look at the documentation a bit. </p> <p>Let's start with the <em>open()</em> function. According to the Python 3.* documentation </p> <blockquote> <p>open() returns a file object, and is most commonly used with two arguments: open(filename, mode). <a href="https://docs.pytho...
1
2016-08-29T20:06:31Z
[ "python", "python-3.x", "unicode", "encoding", "utf-8" ]
Apparently, Python Strings are not 'born equal'
39,213,688
<p>I'm trying to wrap my brain around the 'text encoding standards'. When interpreting a bunch of bytes as 'text', one has to know which 'encoding sheme' applies. Possible candidates that I know of:</p> <ul> <li>ASCII: Very basic encoding scheme, supports 128 characters.</li> <li>CP-1252: Windows encoding scheme for t...
4
2016-08-29T19:24:34Z
39,214,402
<p>What you're hoping for is unfortunately impossible.</p> <p>Files do not contain encoding information and therefore it's impossible to read them as text without providing an encoding or assuming one.</p> <p>When doing things like <code>text = open("myfile.txt").read()</code> there is no one in the world that can te...
0
2016-08-29T20:12:00Z
[ "python", "python-3.x", "unicode", "encoding", "utf-8" ]
Workaround to open COM port for serial communication on client-side (preferably in Python)
39,213,798
<h2>Goal</h2> <p>I have made a website using the Flask framework and am fairly comfortable with HTML, CSS, JS, Python. My goal is to connect an arduino to the <strong>client's</strong> PC's usb port and use serial.write() to send a number to it.</p> <h2>Notes</h2> <p>I have a working example of <a href="http://playg...
0
2016-08-29T19:31:54Z
39,213,984
<blockquote> <p>Is this even doable? I have researched a lot and it seems that this is not doable due to security reasons? </p> </blockquote> <p>You are correct. There is no ability for browsers to access a COM port. It doesn't matter what language or framework you pick, a browser isn't going to give you that access...
0
2016-08-29T19:44:49Z
[ "python", "arduino", "serial-port", "pyserial", "client-side-scripting" ]
random_state maintained when running script again?
39,213,911
<p>Suppose I have a program, called <code>script.py</code>:</p> <pre><code>import pandas as pd import numpy as np from sklearn.cross_validation import train_test_split if __name__ == "__main__": df = pd.DataFrame({"x": [1,2,3,4,5,6,6,5,6,3], "y": [1,1,0,0,0,0,1,0,0,1]}) train, test = train_test_split(df, tes...
0
2016-08-29T19:39:40Z
39,214,159
<p>Random state how nothing to do with when you run your code. The whole concept of specifing random state is to have <strong>exactly the same results every time you run this code with the same parameters</strong>. So as long as you do not change df, test_size and random_state, this function will always return the same...
1
2016-08-29T19:55:39Z
[ "python", "random", "scikit-learn" ]
Dynamically link a Span and a Slider in a python bokeh plot
39,213,949
<p>I am trying to create plots in python using bokeh that allow dynamic visualization of data in bins. It's worth knowing that I am relatively new to python, very new to bokeh, and I know ZERO javascript. I have consulted this:</p> <p><a href="http://stackoverflow.com/questions/38032737/link-a-span-or-cursor-in-betw...
3
2016-08-29T19:42:00Z
39,235,127
<p>Here is a minimal complete example. Note that the recommended way to add annotations like <code>Span</code> is with <code>plot.add_layout</code> as shown below:</p> <pre><code>from bokeh.layouts import row, widgetbox from bokeh.models import Slider, Span, CustomJS from bokeh.plotting import figure, output_file, sho...
2
2016-08-30T18:57:04Z
[ "python", "bokeh" ]
Dynamically link a Span and a Slider in a python bokeh plot
39,213,949
<p>I am trying to create plots in python using bokeh that allow dynamic visualization of data in bins. It's worth knowing that I am relatively new to python, very new to bokeh, and I know ZERO javascript. I have consulted this:</p> <p><a href="http://stackoverflow.com/questions/38032737/link-a-span-or-cursor-in-betw...
3
2016-08-29T19:42:00Z
39,360,644
<p>Thanks to @bigreddot for providing the answer. This is the code that implemented my solution specifically... Now how to do this programmatically for 128 data files... hmmmm..</p> <pre><code> from bokeh.layouts import row, widgetbox from bokeh.models import Span, CustomJS, Slider output_file('Raw_Spect...
0
2016-09-07T03:08:19Z
[ "python", "bokeh" ]
python kafka: how to make each msg consumed only once by group from begining
39,214,046
<p>I am using <a href="http://kafka-python.readthedocs.io/en/master/apidoc/KafkaConsumer.html" rel="nofollow">Kafka consumer</a> here (version 1.3.1). </p> <p>What I am going to acheive: </p> <ul> <li><p>There are 10 partitions. each partition begins with offset 0. </p></li> <li><p>There is a group of consumers (1,2,...
0
2016-08-29T19:47:58Z
39,247,980
<p>If you use consumer groups, Kafka provides at-least-once delivery guarantees, thus, on failure of a consumer an re-assignment of those consumer's partitions some messages might be delivered a second time.</p> <p>If you want to make sure, no message is processed twice, you can switch your pattern to at-most-once del...
0
2016-08-31T11:08:51Z
[ "python", "apache-kafka", "kafka-consumer-api", "python-kafka" ]
wxPython how to get row ID of list item that is double clicked
39,214,079
<p>I am working on a wxPython app in which I have used a wx.ListCtrl with 12 columns. The control gets populated with some values upon clicking a button... let's say Name, Age, Class, House... etc.</p> <p>Now I want to create a double click event which upon double cliking a list item should pop-up a msgbox with the Na...
0
2016-08-29T19:50:00Z
39,214,158
<p><a href="http://xoomer.virgilio.it/infinity77/wxPython/Events/wx.ListEvent.html#methods-summary" rel="nofollow">http://xoomer.virgilio.it/infinity77/wxPython/Events/wx.ListEvent.html#methods-summary</a></p> <p>(typically the variable you named <code>extra</code> is named <code>event</code> or <code>evt</code> ...)<...
0
2016-08-29T19:55:37Z
[ "python", "wxpython", "listctrl" ]
django and internet explorer session loss
39,214,117
<p>I have been trying to find a fix for this all day but no luck.</p> <p>I have a Django 1.9.4 website that works for all major browsers except for IE.</p> <p>I am using eclipse to run the Django site locally for testing.</p> <p>When I log into my site with IE-11 on the local server, it works just fine.</p> <p>When...
1
2016-08-29T19:52:17Z
39,216,058
<p>The problem lies in the timezone difference and the cookie expiry.</p> <p>To test it, I set the SESSION_COOKIE_AGE = 37200 (2hours + 30000seconds) and IE loaded the site just fine.</p> <p>Interesting that chrome and firefox do not have an issue with this.</p>
0
2016-08-29T22:20:30Z
[ "python", "django", "internet-explorer", "session", "gunicorn" ]
Data Conversion Error while applying a function to each row in pandas Python
39,214,164
<p>I have a data frame in pandas in python which resembles something like this - </p> <pre><code> contest_login_count contest_participation_count ipn_ratio 0 1 1 0.000000 1 3 3 0.083333 2 3 ...
1
2016-08-29T19:55:50Z
39,219,950
<p>I think there is problem <code>dtype</code> of some column is not <code>float</code>.</p> <p>You need cast it by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.astype.html" rel="nofollow"><code>astype</code></a>:</p> <pre><code>df['colname'] = df['colname'].astype(float) </code></pre>...
1
2016-08-30T06:10:23Z
[ "python", "function", "pandas", "dataframe", "apply" ]
Python: Creating nested lists of floats using a for loop
39,214,206
<p>I am working with a list of points <code>[(1,2),(3,4),(5,6),(7,8)]</code>. I want to find the euclidean distance from each point to every other point in the list.</p> <p>I then need a new list created to represent each point in the original list, and in the new list I will add the distances relating to that point o...
2
2016-08-29T19:58:25Z
39,214,305
<p>You can use the following nested list comprehension</p> <pre><code>&gt;&gt;&gt; import math &gt;&gt;&gt; [[math.hypot(point[0]-x, point[1]-y) for x,y in points] for point in points] [[0.0, 2.8284271247461903, 5.656854249492381, 8.48528137423857], [2.8284271247461903, 0.0, 2.8284271247461903, 5.656854249492381], ...
3
2016-08-29T20:05:28Z
[ "python", "loops" ]
Python: Creating nested lists of floats using a for loop
39,214,206
<p>I am working with a list of points <code>[(1,2),(3,4),(5,6),(7,8)]</code>. I want to find the euclidean distance from each point to every other point in the list.</p> <p>I then need a new list created to represent each point in the original list, and in the new list I will add the distances relating to that point o...
2
2016-08-29T19:58:25Z
39,214,442
<p>Scikit-learn has a function for this exact problem, and it will probably be the fastest implementation if your array is large.</p> <pre><code>&gt;&gt;&gt;&gt;from sklearn.metrics.pairwise import pairwise_distances &gt;&gt;&gt;&gt;pairwise_distances(mat_ary1) array([[ 0. , 2.82842712, 5.65685425, 8.485281...
2
2016-08-29T20:13:52Z
[ "python", "loops" ]
download django 1.10 to python 3.5
39,214,247
<p>How do I download django for python 3.5? When I run my virtual environment and type:</p> <pre><code>pip install Django </code></pre> <p>I get:</p> <pre><code>Requirement already satisfied (use --upgrade to upgrade): django in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages </code></p...
0
2016-08-29T20:01:39Z
39,214,813
<p>You created your virtualenv with Python 2.7. You should first create a virtualenv with Python 3.5</p> <pre><code>virtualenv -p &lt;path/to/python3.5&gt; &lt;path/to/new/virtualenv&gt; </code></pre> <p>Then activate this new virtualenv, and finally, run <code>pip install django</code> on the virtualenv with Python ...
1
2016-08-29T20:38:54Z
[ "python", "django", "virtualenv" ]
download django 1.10 to python 3.5
39,214,247
<p>How do I download django for python 3.5? When I run my virtual environment and type:</p> <pre><code>pip install Django </code></pre> <p>I get:</p> <pre><code>Requirement already satisfied (use --upgrade to upgrade): django in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages </code></p...
0
2016-08-29T20:01:39Z
39,220,706
<p>Try using:</p> <p>pip3 install Django or even pip3.5 install Django</p> <p>This is what I used, as pip alone picks up python2 pip. I have Django installed for both python2 and python3.</p>
0
2016-08-30T06:55:34Z
[ "python", "django", "virtualenv" ]
If we don't know the number of entries then how to stop a input() loop of while or for
39,214,263
<p>I tried to get input by bigger number entries but it says "index out of range"</p> <p>if we don't know the number of entries then how to stop a input() loop of while or for, in python: </p> <pre><code>while(): listMatch.append(input()) </code></pre> <p>Look what if I have:</p> <pre><code>Djokovic:Murray:2-6,6-7...
-2
2016-08-29T20:03:01Z
39,214,355
<p>add a control loop that checks for input:</p> <pre><code>listMatch =[] while(True): input_value = input() if(input_value == '' or input_value == 'quit'): break listMatch.append(input_value) </code></pre> <p>if no text or quit is entered, loop will break</p>
0
2016-08-29T20:08:20Z
[ "python", "loops", "for-loop", "input", "while-loop" ]
If we don't know the number of entries then how to stop a input() loop of while or for
39,214,263
<p>I tried to get input by bigger number entries but it says "index out of range"</p> <p>if we don't know the number of entries then how to stop a input() loop of while or for, in python: </p> <pre><code>while(): listMatch.append(input()) </code></pre> <p>Look what if I have:</p> <pre><code>Djokovic:Murray:2-6,6-7...
-2
2016-08-29T20:03:01Z
39,214,361
<p>This loop will stop as soon as you just press return (no string entered)</p> <pre><code>listMatch=[] while True: z=input() if z: listMatch.append(z) else: break </code></pre>
0
2016-08-29T20:08:28Z
[ "python", "loops", "for-loop", "input", "while-loop" ]
If we don't know the number of entries then how to stop a input() loop of while or for
39,214,263
<p>I tried to get input by bigger number entries but it says "index out of range"</p> <p>if we don't know the number of entries then how to stop a input() loop of while or for, in python: </p> <pre><code>while(): listMatch.append(input()) </code></pre> <p>Look what if I have:</p> <pre><code>Djokovic:Murray:2-6,6-7...
-2
2016-08-29T20:03:01Z
39,214,379
<pre><code>listMatch = [] while True: # get the user's input stuff = input() # if they typed "quit", stop looping if stuff == 'quit': break # otherwise append their input to the list and keep on looping listMatch.append(stuff) </code></pre>
0
2016-08-29T20:10:00Z
[ "python", "loops", "for-loop", "input", "while-loop" ]
method within class is not callable within that class?
39,214,277
<p>If I have a file, foo.py with contents:</p> <pre><code>import pandas as pd class Marcher(object): def __init__(self, p_path): self.p_path = p_path p_m = 'ID' def first_call(self): df_p = pd.read_csv(self.p_path, header=None) return df_p def p_to_i(self, p): pii = ...
0
2016-08-29T20:03:56Z
39,214,416
<p>why do you want <code>m1</code> to be a class member variable? just move the call like this:</p> <pre><code>def __init__(self, path): self.path = path self.m1 = self.p_to_i(self.first_call()) </code></pre>
2
2016-08-29T20:12:40Z
[ "python" ]
method within class is not callable within that class?
39,214,277
<p>If I have a file, foo.py with contents:</p> <pre><code>import pandas as pd class Marcher(object): def __init__(self, p_path): self.p_path = p_path p_m = 'ID' def first_call(self): df_p = pd.read_csv(self.p_path, header=None) return df_p def p_to_i(self, p): pii = ...
0
2016-08-29T20:03:56Z
39,214,483
<p>The issue is you're trying to call the methods before creating an instance. Take for instance a simple Circle class:</p> <pre><code>import math class Circle(object): def __init__(self, radius): self.radius = radius def get_area(self): return math.pi * self.radius ** 2 # You cannot do th...
2
2016-08-29T20:16:17Z
[ "python" ]
SyntaxError: python Arabic encoding
39,214,320
<p>I have this Code -I am using Python 2.7- :</p> <pre><code>#!/usr/bin/python # -*- Coding: UTF-8 -*- import nltk from nltk.tokenize import StanfordTokenizer sentence = u"السلام عليكم و رحمة الله و بركاته" print StanfordTokenizer().tokenize(sentence) </code></pre> <p>I saved the code in a ...
1
2016-08-29T20:06:20Z
39,214,374
<blockquote> <p>... the first or second line must match the regular expression "^[ \t\v]<em>#.</em>?coding[:=][ \t]*([-_.a-zA-Z0-9]+)".</p> </blockquote> <p><a href="https://www.python.org/dev/peps/pep-0263/" rel="nofollow">source</a></p> <p>Your encoding declaration does not match that regex. The <code>c</co...
1
2016-08-29T20:09:17Z
[ "python", "encoding", "arabic" ]
scrape Url and text from website using lxml python
39,214,339
<p>I don't know much about lxml and xpaths and I want to learn how to scrape data from website. When I run this code I don't get any results and don't know why. Please help me to fix it.</p> <p>code here</p> <pre><code>from lxml import html import requests pageLen=str(100) page = requests.get('http://www.yellowpages....
-1
2016-08-29T20:07:17Z
39,214,818
<p>quick and dirty:</p> <pre><code>from lxml import html import requests url = 'http://www.yellowpages.com/search?search_terms=lawyer&amp;geo_location_terms=usa&amp;page=2' page = requests.get(url) tree = html.fromstring(page.text) tree.make_links_absolute(url) for business in tree.xpath('//a[@class="business-name"]'...
-1
2016-08-29T20:39:23Z
[ "python", "web-scraping", "lxml" ]