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 |
|---|---|---|---|---|---|---|---|---|---|
How can I find where files are used as links in html pages? | 38,221,403 | <p>I have a static website where versions of old pages are still stored in the root. I want to find these pages and look if they are used in some link somewhere in the root's files. <br>
So I made a list of all the files inside the root using powershell's command <code>ls -R -Name</code> and store it on a file 'filelis... | 1 | 2016-07-06T10:08:30Z | 38,222,057 | <p>Since you are sure that the file names contain <code>'.'</code>, each path can be split on <code>'\'</code> and checked if it contains <code>'.'</code>. Also, stripping each line would remove new line characters.</p>
<pre><code>with open('filelist.txt') as f:
for l in f:
l= l.strip()
if '.' in l.spl... | 0 | 2016-07-06T10:41:46Z | [
"python",
"html",
"regex"
] |
python Long to Byte Array of 2 byte using struct | 38,221,433 | <p>I am converting long or int to bytearray in python using struct</p>
<p>ba = struct.pack('H',12)</p>
<p>output : '\x0c\x00'
length 2 bytes</p>
<p>but if i convert
ba = struct.pack('H',12345)</p>
<p>output : '90'
i need to encode to hex for desired out put
ba.encode('hex')
in this case output is
output : 3930
an... | 0 | 2016-07-06T10:10:12Z | 38,221,756 | <p><code>'90'</code> is two bytes. The first byte is 0x39 and the second is 0x30.</p>
<pre><code>>>> hex(12345)
'0x3039'
</code></pre>
<p><strong>TL;DR:</strong> You are getting the correct result.</p>
| 0 | 2016-07-06T10:25:45Z | [
"python",
"python-2.7",
"bytearray"
] |
takefocus = NO fails to prevent tkinter.ttk.Notebook tabs from taking focus | 38,221,559 | <p>In the following example, I have set the Notebook to not take focus, so that its tabs get skipped over while navigating from widget to widget using the shortcuts supported by <code>enable_traversal()</code>. This mostly works, but not entirely. If a tab is already being displayed (but doesn't have focus), pressing i... | 0 | 2016-07-06T10:16:07Z | 38,224,928 | <p>Why then add <code>underline=0</code>? Remove that piece of code in both the lines. Also, add another argument <code>takefocus=False</code> while adding the tabs. And remove <code>takefocus</code> when you are creating the notebook.</p>
| 0 | 2016-07-06T13:11:17Z | [
"python",
"tkinter",
"ttk"
] |
Pandas: Select balanced sample | 38,221,584 | <p>I have a data frame with 3000 companies covering five years.</p>
<pre><code>Id Company Year Value
0 1111111 2016 NaN
1 1111111 2015 3871.0
2 3333333 2016 3989.0
3 3333333 2015 3648.0
4 4444444 2016 5... | 0 | 2016-07-06T10:17:17Z | 38,222,807 | <p>groupby.count() returns the number of non-null values so if you groupby companies, the count should be equal to the number of years. Assuming no duplicates, you can do this:</p>
<pre><code>df.ix[df.groupby('Company')['Value'].transform('count') > 1, :]
Out[259]:
Id Company Year Value
2 2 3333333 2016... | 1 | 2016-07-06T11:22:32Z | [
"python",
"python-2.7",
"pandas"
] |
How to make integer patterns? | 38,221,656 | <p>I want to build a sequence pattern, for example i have numbers <code>1</code>, <code>2</code>, <code>3</code>.<br>
<code>1</code> is first pattern, <code>2</code> is second, and <code>3</code> is third.</p>
<pre><code># Assign all patterns.
First = 1
Second = 2
Third = 3
# Make a loop
for x in xrange(1, 100):
... | 0 | 2016-07-06T10:20:46Z | 38,221,694 | <p><code>xrange</code> has a step parameter. See the <a href="https://docs.python.org/2/library/functions.html#xrange" rel="nofollow">documentation</a>.</p>
<pre><code>for x in xrange(1, 100, 2):
print(Second)
</code></pre>
<p>To print Pattern 1, 2 and 3 successively:</p>
<pre><code>patterns = [First, Second, Th... | 2 | 2016-07-06T10:22:29Z | [
"python",
"sequence"
] |
How to make integer patterns? | 38,221,656 | <p>I want to build a sequence pattern, for example i have numbers <code>1</code>, <code>2</code>, <code>3</code>.<br>
<code>1</code> is first pattern, <code>2</code> is second, and <code>3</code> is third.</p>
<pre><code># Assign all patterns.
First = 1
Second = 2
Third = 3
# Make a loop
for x in xrange(1, 100):
... | 0 | 2016-07-06T10:20:46Z | 38,221,720 | <p>You need to add an <code>if statement</code> with a <code>modulo operator(%)</code> like this:</p>
<pre><code># Assign all patterns.
First = 1
Second = 2
Third = 3
# Make a loop
for x in xrange(1, 100):
print x
if x % 2 == 0:
print(Second)
</code></pre>
| 2 | 2016-07-06T10:24:04Z | [
"python",
"sequence"
] |
Unpacking list of lists generated by a zip into one list | 38,221,981 | <p>I am again manipulating dataframes.
Here I concatenate multiple dataframe using row as common reference.
Then I want to reorder the columns by "pairing" the first one columns of each df together, and so on. All for the sake of data readability</p>
<p>Here is my code:</p>
<pre><code>df_list=[df_1,df_2,df_3]
retu... | 0 | 2016-07-06T10:37:50Z | 38,222,658 | <p>You may just zip all column lists and then flatten the list of lists</p>
<pre><code>list_columns = [ col for cols in zip( *dfcolumns_list ) for col in cols ]
</code></pre>
| 1 | 2016-07-06T11:13:39Z | [
"python",
"pandas",
"dataframe",
"zip",
"multiple-columns"
] |
tensorflow efficient way for tensor multiplication | 38,222,126 | <p>I have two tensors in tensorflow, the first tensor is 3-D, and the second is 2D. And I want to multiply them like this:</p>
<pre><code>x = tf.placeholder(tf.float32, shape=[sequence_length, batch_size, hidden_num])
w = tf.get_variable("w", [hidden_num, 50])
b = tf.get_variable("b", [50])
output_list = []
for ste... | 0 | 2016-07-06T10:46:21Z | 38,222,999 | <p>You could use <code>batch_matmul</code>. Unfortunately it doesn't seem <code>batch_matmul</code> supports broadcasting along the batch dimension, so you have to tile your <code>w</code> matrix. This will use more memory, but all operations will stay in TensorFlow</p>
<pre><code>a = tf.ones((5, 2, 3))
b = tf.ones((3... | 0 | 2016-07-06T11:32:48Z | [
"python",
"tensorflow",
"deep-learning"
] |
tensorflow efficient way for tensor multiplication | 38,222,126 | <p>I have two tensors in tensorflow, the first tensor is 3-D, and the second is 2D. And I want to multiply them like this:</p>
<pre><code>x = tf.placeholder(tf.float32, shape=[sequence_length, batch_size, hidden_num])
w = tf.get_variable("w", [hidden_num, 50])
b = tf.get_variable("b", [50])
output_list = []
for ste... | 0 | 2016-07-06T10:46:21Z | 38,228,782 | <p>You could use <a href="https://www.tensorflow.org/versions/r0.9/api_docs/python/functional_ops.html#map_fn" rel="nofollow"><code>map_fn</code></a>, which scans a function along the first dimension.</p>
<pre><code>x = tf.placeholder(tf.float32, shape=[sequence_length, batch_size, hidden_num])
w = tf.get_variable("... | 0 | 2016-07-06T16:15:16Z | [
"python",
"tensorflow",
"deep-learning"
] |
Why exc_traceback returns None | 38,222,138 | <p><a href="https://docs.python.org/2/library/sys.html?highlight=sys#sys.exc_info" rel="nofollow">sys.exc_info()</a> returns a tuple (type , value, traceback).<br>
so <code>sys.exc_info()[2]</code> is our traceback object. </p>
<p>Why it does not catch exceptions traceback with this code:</p>
<pre><code>import sys
... | 1 | 2016-07-06T10:46:51Z | 38,222,488 | <p>You see <code>None</code> because <em>there is no outer frame</em>. You're executing this directly, so the current frame is the last frame. To demonstrate this, I created a <code>demo.py</code>:</p>
<pre><code>import sys
try:
1/0
except ZeroDivisionError:
print sys.exc_info()[2].tb_frame.f_back
</code></pr... | 2 | 2016-07-06T11:04:51Z | [
"python",
"exception",
"sys",
"traceback"
] |
Return dynamic arrays by ref in Swig | 38,222,167 | <p>I'm using swig to wrap some code in c++ to use in Python.<br>
I have a function that get array and return 2 dynamic arrays (the function get them by ref) after some calculation on the input array.<br>
My problem is that the output arrays are unspecified size, because the size depends on the input array.<br>
My Funct... | 1 | 2016-07-06T10:48:33Z | 38,252,700 | <p>Here goes an answer, which uses double pointers rather than *&. You can make a simple wrapper function to support this prototype</p>
<p>Please note that the returned arrays are allocated and the typemap generates a proxy which ensures that the arrays are deleted when deleted in Python. They are managed</p>
<p>... | 0 | 2016-07-07T18:21:34Z | [
"python",
"c++",
"arrays",
"numpy",
"swig"
] |
raise ValueError(item) when trying to display table in SparkSQL | 38,222,175 | <p>I have the following code using PySpark and SparkSQL where I am trying to create a DataFrame, save it as a table and then show that table:</p>
<pre><code>schema = StructType([StructField("int_field", IntegerType()),
StructField("string_field", StringType())])
dfRow = sqlContext.createDataF... | 0 | 2016-07-06T10:48:56Z | 38,247,099 | <p>You must have missed something in your snippet. The error complains that it cannot find <code>id</code> which is not in your sample.</p>
<pre><code>from pyspark.sql.types import StringType, StructField, StructType, IntegerType
simulation = [
(1, 'a'),
(2, 'b')
]
schema = StructType(
[StructField("int_... | 0 | 2016-07-07T13:43:07Z | [
"python",
"apache-spark",
"pyspark",
"apache-spark-sql"
] |
socket set blocking raising OSError: [Errno 11] Resource temporarily unavailable | 38,222,180 | <p>I am creating a socket and using it to communicate to python processes.</p>
<p>I create the socket this way because I already have a file descriptor:</p>
<pre><code>sock = socket.fromfd(fd, socket.AF_INET, socket.SOCK_STREAM)
</code></pre>
<p>If I receive a lot of requests it will raise a [Errno 11] Resource tem... | 0 | 2016-07-06T10:49:01Z | 38,230,228 | <p>Firstly, I have no idea what a "python process" is. A process is a process. What language something is written in, or what interpreter may be interpreting something, has nothing to do with anything.</p>
<p>Next, I am not sure what "I create the socket this way because I already have a file descriptor" means. I d... | -3 | 2016-07-06T17:34:38Z | [
"python",
"sockets",
"unix"
] |
I have a csv file with two different formats of date value, want them to be in any single format | 38,222,302 | <p>My CSV file looks like this</p>
<pre><code>id date
1602 11/23/2015 14:10
1602 11/23/2015 22:45
1602 18/10/2011 09:19:46 AM
1702 18/10/2011 09:07:33 AM
1863 18/10/2011 09:07:35 AM
1436 18/10/2011 09:07:36 AM
</code></pre>
<p>I'm looking for output like</p>
<p>id date
1602 11/23/... | -9 | 2016-07-06T10:54:50Z | 38,230,753 | <p>I'm not sure why you are making this so much more difficult than it is. It seems that all you are actually doing is (1) getting rid of the first line of the CSV file; (2) tossing out any quotation marks; (3) mapping sets of spaces/tabs into single spaces; and (4) mapping newlines to spaces.</p>
<p>SO . . . how abo... | 0 | 2016-07-06T18:01:51Z | [
"java",
"python",
"shell"
] |
Set alternative pk in Django | 38,222,360 | <p>I would like to make Django generate 6+ digits number id's for one <code>Model</code>. I don't want to start from zero but I want this id's to be clear and readable by users. So the good one is for example: <strong>658975</strong></p>
<p>How to do that?</p>
<p>I've tried this:</p>
<pre><code>class MyUUIDModel(mod... | 0 | 2016-07-06T10:58:34Z | 38,222,419 | <p>Can't you simply use pk+random number to show to the user and keeping the rest of the logic same ?</p>
<p>Else here you go <a href="http://stackoverflow.com/questions/2130635/how-to-make-a-primary-key-start-from-1000">How to make a primary key start from 1000?</a></p>
<p>Write a one of migration for this.</p>
| 0 | 2016-07-06T11:01:17Z | [
"python",
"django",
"primary-key",
"django-database"
] |
Set alternative pk in Django | 38,222,360 | <p>I would like to make Django generate 6+ digits number id's for one <code>Model</code>. I don't want to start from zero but I want this id's to be clear and readable by users. So the good one is for example: <strong>658975</strong></p>
<p>How to do that?</p>
<p>I've tried this:</p>
<pre><code>class MyUUIDModel(mod... | 0 | 2016-07-06T10:58:34Z | 38,222,718 | <p>The best options to set the primary key to start from <code>100000</code>. For example(MySQL),</p>
<pre><code>ALTER TABLE django_app_table_name AUTO_INCREMENT = 100000
</code></pre>
<p>Since these commands are depends on the database vendor, it is better to write a our own custom migration using the Django migrati... | 0 | 2016-07-06T11:16:38Z | [
"python",
"django",
"primary-key",
"django-database"
] |
If a django migration is migrated to db, what is the best practice if the migration is deleted at a later date? | 38,222,375 | <p>While this shouldn't happen its not impossible.</p>
<p>So what to do in the event that a migration has been run into a database and the migration file has then been deleted and is not recoverable?</p>
<p>this assumes that the database cannot just be dropped.</p>
| 0 | 2016-07-06T10:59:14Z | 38,225,266 | <p>The first approach I'd try would be to check out the last good commit and recreate the model changes in question so the migration could be regenerated and checked in. </p>
<p>And while it's good to have a contingency plan for things like this, if it's a real concern I'd suggest evaluating your deployment process to... | 0 | 2016-07-06T13:28:50Z | [
"python",
"sql",
"django",
"migration"
] |
Python Gtk 3 window is not defined, class instancing confusion | 38,222,407 | <p>I am just starting to get into python and I am utterly confused as to how object creation works. I am trying to create user interface with GTK. Here is an example of the problem I am having:</p>
<pre><code>from gi.repository import Gtk
def button_clicked(self, button):
self.button_label = button.get_label()
... | 0 | 2016-07-06T11:00:47Z | 38,222,627 | <p>It is because you are starting the main loop (<code>Gtk.main()</code>) inside of <code>LoginWindow.__init__()</code>. That means that the <code>window = LoginWindow()</code> line doesn't finish executing until after the login window is closed. You should take <code>Gtk.main()</code> outside of the <code>__init__</... | 2 | 2016-07-06T11:11:53Z | [
"python",
"gtk3"
] |
Remove first and last character from csv file using python | 38,222,683 | <p>I need to transpose the following file output1.csv, which is is a result from a quantum chemistry calculation into a single colum efficiently:</p>
<pre><code> Frequencies -- 18.8210 44.7624 46.9673
Frequencies -- 66.6706 102.0432 112.4930
Frequencies... | 0 | 2016-07-06T11:14:52Z | 38,229,370 | <p>the user <a href="http://codereview.stackexchange.com/users/39848/edward">http://codereview.stackexchange.com/users/39848/edward</a> helped here </p>
<p><a href="http://codereview.stackexchange.com/questions/134045/optimize-a-simple-and-quick-python-script-for-transposing-a-csv-file/134064#134064">http://codereview... | 0 | 2016-07-06T16:46:38Z | [
"python",
"regex",
"csv",
"pandas"
] |
Normalize adjency matrix (in pandas) with MinMaxScaler | 38,222,717 | <p>I have an adjency matrix (dm) of items vs items; the value between two items (e.g., item0,item1) refers to the number of times these items appear together. How can I scale all the values in pandas between 0 to 1?</p>
<pre><code>from sklearn import preprocessing
scaler = preprocessing.MinMaxScaler()
</code></pre>
<... | 0 | 2016-07-06T11:16:38Z | 38,223,157 | <p>You can assign the resulting array back to the dataframe with loc:</p>
<pre><code>df = pd.DataFrame(np.random.randint(1, 5, (5, 5)))
df
Out[277]:
0 1 2 3 4
0 2 3 2 3 1
1 2 3 4 4 2
2 2 3 4 3 2
3 1 1 2 1 4
4 4 2 2 3 1
df.loc[:,:] = scaler.fit_transform(df)
df
Out[279]:
0... | 0 | 2016-07-06T11:41:48Z | [
"python",
"pandas",
"normalization",
"adjacency-matrix"
] |
Running Half life codes for a mean reverting series | 38,222,743 | <p>I am currently trying to compute the Half life results for multiple columns of data. I have tried to incorporate the codes I got from 'pythonforfinance.com' <a href="http://www.pythonforfinance.net/2016/05/09/python-backtesting-mean-reversion-part-2/" rel="nofollow">Link</a>.</p>
<p>However, I seem to have missed a... | 0 | 2016-07-06T11:17:52Z | 38,225,134 | <p>As explained by the error message, <code>pd.Series.ix</code>isn't callable: you should change <code>spread_lag.ix([0])</code> to <code>spread_lag.ix[0]</code>.</p>
<p>Also, you shouldn't shift on <code>axis=1</code> (rows) since you're interested in differences along each column (<code>axis=0</code>, default value)... | 1 | 2016-07-06T13:21:33Z | [
"python",
"numpy",
"pandas",
"statsmodels"
] |
how to join three tables and show the items based on timestamps in django | 38,222,746 | <p>Friends, I am working on a site that shows a registered user his/her customized news feed based on the users they follow. What I want is that they should see the items from three models Question, Answer and Document, based on these items' timestamps.All my models have a timestamps field. How can I implement it?</p>
... | 0 | 2016-07-06T11:18:00Z | 38,222,850 | <p>Assume that you have a field called <code>created_at</code> in all the models.</p>
<p><strong>Step 1: Merge all 3 lists.</strong></p>
<pre><code>merged_list = []
merged_list.extend(questions)
merged_list.extend(answers)
merged_list.extend(docs)
</code></pre>
<p><strong>Step 2: Sort by the common field.</strong></... | 1 | 2016-07-06T11:24:54Z | [
"python",
"django"
] |
how to join three tables and show the items based on timestamps in django | 38,222,746 | <p>Friends, I am working on a site that shows a registered user his/her customized news feed based on the users they follow. What I want is that they should see the items from three models Question, Answer and Document, based on these items' timestamps.All my models have a timestamps field. How can I implement it?</p>
... | 0 | 2016-07-06T11:18:00Z | 38,222,858 | <p>You can <code>chain</code> the objects, and sort using the common <code>timestamp</code> field of your models:</p>
<pre><code>from itertools import chain
def index(request):
items = sorted(chain(Question.objects.all(),
Answer.objects.all(),
Document.objects.all... | 1 | 2016-07-06T11:25:20Z | [
"python",
"django"
] |
How to efficiently compare rows in a pandas DataFrame? | 38,222,751 | <p>I have a pandas dataframe containing a record of lightning strikes with timestamps and global positions in the following format:</p>
<pre><code>Index Date Time Lat Lon Good fix?
0 1 20160101 00:00:00.9962692 -7.1961 -60.7604 1
1 2 ... | 5 | 2016-07-06T11:18:22Z | 38,225,819 | <p>You can use some unsupervised ML algorithms for improving speed.
Before using ML algorithms need a do some data transformation.
For example:</p>
<ol>
<li>transform "Date","Timestamp" into one column feature "Timestamp".</li>
<li>It's possible to use raw "Lat","Lon" but it's maybe helpful when we merge them in one.... | 0 | 2016-07-06T13:55:25Z | [
"python",
"numpy",
"pandas"
] |
How to efficiently compare rows in a pandas DataFrame? | 38,222,751 | <p>I have a pandas dataframe containing a record of lightning strikes with timestamps and global positions in the following format:</p>
<pre><code>Index Date Time Lat Lon Good fix?
0 1 20160101 00:00:00.9962692 -7.1961 -60.7604 1
1 2 ... | 5 | 2016-07-06T11:18:22Z | 38,225,939 | <p>This is one of those problems that seems easy initially but the more your think about it the more your head melts! We have essentially got a three-dimensional (Lat, Lon, Time) clustering problem, followed by filtering based on cluster size. There are a number of questions a little like this (though more abstract) an... | 1 | 2016-07-06T14:00:57Z | [
"python",
"numpy",
"pandas"
] |
How to efficiently compare rows in a pandas DataFrame? | 38,222,751 | <p>I have a pandas dataframe containing a record of lightning strikes with timestamps and global positions in the following format:</p>
<pre><code>Index Date Time Lat Lon Good fix?
0 1 20160101 00:00:00.9962692 -7.1961 -60.7604 1
1 2 ... | 5 | 2016-07-06T11:18:22Z | 38,227,184 | <p>This answer might not be very efficient. I'm facing a very similar problem and am currently looking for something more efficient than what I do because it still takes one hour to compute on my dataframe (600k rows).</p>
<p>I first suggest you don't even think about using <code>for</code> loops like you do. You migh... | 2 | 2016-07-06T14:55:58Z | [
"python",
"numpy",
"pandas"
] |
How to efficiently compare rows in a pandas DataFrame? | 38,222,751 | <p>I have a pandas dataframe containing a record of lightning strikes with timestamps and global positions in the following format:</p>
<pre><code>Index Date Time Lat Lon Good fix?
0 1 20160101 00:00:00.9962692 -7.1961 -60.7604 1
1 2 ... | 5 | 2016-07-06T11:18:22Z | 38,240,416 | <p>Depending on your data, this might be useful or not. Some strikes may be "isolated" in time, i.e. further away from the strike before and the strike after than the time-threshold. You could use these strikes to separate your data into groups, and you can then process those groups using <code>searchsorted</code> alon... | 2 | 2016-07-07T08:04:17Z | [
"python",
"numpy",
"pandas"
] |
Is it possible to combine a dictionary of lists together into one list? | 38,222,868 | <p>Say I have a dictionary like so:</p>
<pre><code>my_list = {
"foo": ["a", "b", "c"],
"bar": ["d", "e", "f"]
}
</code></pre>
<p>How could I combine all lists in this dictionary into one large list in one line of code (meaning there would not be a temporary variable)? I came up with the following solution, ho... | 1 | 2016-07-06T11:26:03Z | 38,222,974 | <p>This should do:</p>
<pre><code>result = sorted(sum(my_list.values(), []))
</code></pre>
<p>Remove <code>sorted</code> if your result does not need to be <em>sorted</em></p>
| 1 | 2016-07-06T11:31:42Z | [
"python",
"dictionary"
] |
Is it possible to combine a dictionary of lists together into one list? | 38,222,868 | <p>Say I have a dictionary like so:</p>
<pre><code>my_list = {
"foo": ["a", "b", "c"],
"bar": ["d", "e", "f"]
}
</code></pre>
<p>How could I combine all lists in this dictionary into one large list in one line of code (meaning there would not be a temporary variable)? I came up with the following solution, ho... | 1 | 2016-07-06T11:26:03Z | 38,223,059 | <p>You can use <code>itertools</code>.</p>
<pre><code>import itertools
combined_results = list(itertools.chain.from_iterable(my_list.values()))
</code></pre>
| 1 | 2016-07-06T11:35:37Z | [
"python",
"dictionary"
] |
Is it possible to combine a dictionary of lists together into one list? | 38,222,868 | <p>Say I have a dictionary like so:</p>
<pre><code>my_list = {
"foo": ["a", "b", "c"],
"bar": ["d", "e", "f"]
}
</code></pre>
<p>How could I combine all lists in this dictionary into one large list in one line of code (meaning there would not be a temporary variable)? I came up with the following solution, ho... | 1 | 2016-07-06T11:26:03Z | 38,223,142 | <p>don't use <code>sum</code> to join lists. There is a long discussion on the python ideas mailing list around why that is a bad idea (will get link later).</p>
<p><code>itertools.chain</code> is a good solution, or if you rather go functional then</p>
<pre><code>>>> my_list = {
... "foo": ["a", "b", "... | 2 | 2016-07-06T11:40:31Z | [
"python",
"dictionary"
] |
Django: Use htaccess to protect django app | 38,222,962 | <p>I have a staging server with identical source code to the production server.
I want to keep the public outside of the staging server so I thought of using htaccess to limit users to the staging server (and keep robots and strangers outside).</p>
<p>Somehow its not working for me.</p>
<p>I created the passwordfile<... | 1 | 2016-07-06T11:31:06Z | 38,232,083 | <p>I found an alternative solution to the above goal without htaccess.
I would like to share:</p>
<p>in 000-default-conf in the respective virtualhost section:</p>
<pre><code><Directory /var/www/djangoapp/djangoapp>
AuthUserFile /var/.htpasswd
AuthName "Just testing"
AuthType Basic
... | 0 | 2016-07-06T19:17:25Z | [
"python",
"django",
"apache",
".htaccess"
] |
Python output on a separate lines | 38,223,034 | <p>I have a simple question about Python.
I wrote a working script but when I execute it, it gives me an answer in one line, as a string.
What I am looking is an answer to be on two separate lines.
Here is a code:
<a href="http://i.stack.imgur.com/jt9Gy.png" rel="nofollow">Python code</a></p>
<pre><code>def test... | -4 | 2016-07-06T11:34:30Z | 38,225,387 | <p>You are removing the newline characters "\n" from each line in the file with the statement:-</p>
<p><strong>line=line.strip()</strong></p>
<p>Just remove it and it should work correctly.</p>
| 0 | 2016-07-06T13:35:41Z | [
"python"
] |
Python: AttributeError: 'str' object has no attribute 'readlines' | 38,223,058 | <p>I am trying to copy text from <code>mobileBuildSettings</code> and use it to replace text from <code>abproject</code>. I am getting the following error and I don't understand it.</p>
<pre><code>AttributeError: 'str' object has no attribute 'readlines'
</code></pre>
<p>Below is my code:</p>
<pre><code>with open("C... | -6 | 2016-07-06T11:35:34Z | 38,223,290 | <p>I changed:</p>
<pre><code>for line in abproject.readlines():
</code></pre>
<p>to:</p>
<pre><code>for line in script.readlines():
</code></pre>
| 0 | 2016-07-06T11:49:17Z | [
"python",
"file",
"text",
"replace"
] |
Python: AttributeError: 'str' object has no attribute 'readlines' | 38,223,058 | <p>I am trying to copy text from <code>mobileBuildSettings</code> and use it to replace text from <code>abproject</code>. I am getting the following error and I don't understand it.</p>
<pre><code>AttributeError: 'str' object has no attribute 'readlines'
</code></pre>
<p>Below is my code:</p>
<pre><code>with open("C... | -6 | 2016-07-06T11:35:34Z | 38,223,334 | <p>In order to give a good answer to jill1993's question and take the MosesKoledoye's answer :</p>
<pre><code>abproject = ("C:/abproject.build")
</code></pre>
<p><code>abproject</code> is a string object. Furthermore, you write :</p>
<pre><code>with open("C:/abproject.build", "r+") as script
</code></pre>
<p>So if ... | 0 | 2016-07-06T11:51:45Z | [
"python",
"file",
"text",
"replace"
] |
Dictionary with costs by weight | 38,223,106 | <p>today I would like to embed shipping price table to python dictionary and I have not idea how to start.</p>
<h2><strong>What I have?</strong></h2>
<pre><code>I have table with shipping costs and zones.
+-----------+------+---------+--------+
| weight | Asia | America | Europe |
+-----------+------+... | 1 | 2016-07-06T11:38:23Z | 38,223,332 | <p>It's quite OK, but you need to correct your edge conditions - check for "less than or equal" instead of "less than", or cases like <code>500</code> will produce incorrect results:</p>
<pre><code>if zone['min_w'] <= product_weight <= zone['max_w']:
</code></pre>
<p>Also, there's a typo - the closing parenthes... | 2 | 2016-07-06T11:51:34Z | [
"python",
"dictionary",
"range"
] |
How to upload and access a Python script in cPanel? | 38,223,230 | <p>I have a Python file, which is an automation script from GitHub. I want that script to be executed by a PHP page.</p>
<p>For example, I have an <code>index.php</code> page, and it has a button saying <code>Start script</code>. Upon clicking the button, a Python script, <code>instabot.py</code>, should be executed. ... | -1 | 2016-07-06T11:45:51Z | 38,224,633 | <p>Using information from <a href="http://stackoverflow.com/questions/31811253/execute-python-script-from-php">another StackOverflow post</a>, you might wanna use <code>exec()</code> to run a Python script from PHP. Like:</p>
<pre><code>exec('python /path/to/file/instabot.py');
</code></pre>
<p>According to Hostgator... | 0 | 2016-07-06T12:58:27Z | [
"php",
"python",
"execute"
] |
How to parse tuples that has no delimiters? | 38,223,316 | <p>I'm using pyparser and want to parse files that contain tree structure with values stored after equals sign with no actual delimiters otherwise. </p>
<p>I've done all the parsing so well except for rare cases when data is stored in multiple lines, so I have to rewrite parser not to stop grabbing value as something ... | 3 | 2016-07-06T11:50:53Z | 38,224,805 | <p>You are on the right track with <code>~FollowedBy</code>, but these expressions have to be part of the <code>OneOrMore</code> repetitive expression. Something like:</p>
<pre><code>multilineString = Group(token + equals + OneOrMore(stringTemplate + ~FollowedBy(equals)))
for match in multilineString.searchString(test... | 1 | 2016-07-06T13:06:10Z | [
"python",
"python-3.x",
"parsing",
"pyparsing"
] |
sending and receive data from client using python | 38,223,347 | <p>I am using
<a href="http://en.usr.cn/Wifi-Serial-Server/RS485-to-WIFI-802.11-B-G-N-Converter.html" rel="nofollow">RS485 to wifi router</a></p>
<p>above model for Rs485 communication.</p>
<p>Intailly I tried simple code with arduino. WIth sending serial data over client for every 2S.</p>
<pre><code>void setup()
... | 0 | 2016-07-06T11:52:33Z | 38,239,636 | <p>I have modified code i am getting response. Need to help to convert data into decimal format. to understna received data correct or not. I need to convert whole data into decimal format. Let me know how can achieve this</p>
<pre><code>import socket
TCP_IP = '192.168.1.3'
TCP_PORT = 8899
BUFFER_SIZE = 1000
s = sock... | 0 | 2016-07-07T07:19:05Z | [
"python",
"python-2.7",
"sockets",
"wifi",
"tcpclient"
] |
Foreign Key Constraint Failed in Sqlite3 | 38,223,384 | <p>I'm executing this script for the second time(these tables exist previously) and am getting a Foreign Key Constraint Failed error. I'm a beginner in Sqlite3 and am not able to figure out the cause behind it. </p>
<p>Schema.sql </p>
<pre><code>PRAGMA foreign_keys = 1;
drop table if exists user;
create table user(u... | 0 | 2016-07-06T11:54:40Z | 38,223,557 | <p>You set owner, which is text, as a foreign key. Try setting it as an integer.</p>
| -1 | 2016-07-06T12:04:22Z | [
"python",
"sqlite",
"flask",
"sqlite3"
] |
Foreign Key Constraint Failed in Sqlite3 | 38,223,384 | <p>I'm executing this script for the second time(these tables exist previously) and am getting a Foreign Key Constraint Failed error. I'm a beginner in Sqlite3 and am not able to figure out the cause behind it. </p>
<p>Schema.sql </p>
<pre><code>PRAGMA foreign_keys = 1;
drop table if exists user;
create table user(u... | 0 | 2016-07-06T11:54:40Z | 38,226,221 | <p>When you are dropping a table, the effect is the same as if you were deleting all rows, and these deletions can fail.</p>
<p>Drop all the tables first, and in the correct order (<code>asset</code> first).</p>
| 0 | 2016-07-06T14:13:12Z | [
"python",
"sqlite",
"flask",
"sqlite3"
] |
How can I visualize a 3D volume with Python? | 38,223,423 | <p>Similar to how there's <a href="https://www.mathworks.com/matlabcentral/fileexchange/22940-vol3d-v2" rel="nofollow">vol3d</a> for Matlab, how can I visualize a 3D-Array in Python? I'm currently working with Matplotlib but I'll take whatever works.</p>
| 2 | 2016-07-06T11:56:55Z | 38,223,446 | <p>You are probably looking for <a href="http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#surface-plots" rel="nofollow">mplot3d <code>plot_surface</code></a>, which is part of <code>matplotlib</code>. Examples are provided in the link.</p>
| 1 | 2016-07-06T11:58:39Z | [
"python",
"matplotlib"
] |
How can I visualize a 3D volume with Python? | 38,223,423 | <p>Similar to how there's <a href="https://www.mathworks.com/matlabcentral/fileexchange/22940-vol3d-v2" rel="nofollow">vol3d</a> for Matlab, how can I visualize a 3D-Array in Python? I'm currently working with Matplotlib but I'll take whatever works.</p>
| 2 | 2016-07-06T11:56:55Z | 38,234,641 | <p><a href="http://docs.enthought.com/mayavi/mayavi/mlab.html" rel="nofollow">Mayavi</a> has some good API for 3D plotting in python</p>
| 1 | 2016-07-06T22:11:28Z | [
"python",
"matplotlib"
] |
Add columns to pandas dataframe containing max of each row, AND corresponding column name | 38,223,461 | <p><strong>My system</strong></p>
<p>Windows 7, 64 bit</p>
<p>python 3.5.1</p>
<p><strong>The challenge</strong></p>
<p>I guess this should be easy, but to the best of my abilities it's hard to accomplish and even difficult to explain. I hope the reproducible example below sheds some light on the problem. A similar... | 1 | 2016-07-06T11:59:23Z | 38,223,552 | <p>You can compare the df against <code>maxval</code> using <code>eq</code> with <code>axis=0</code>, then use <code>apply</code> with a <code>lambda</code> to produce a boolean mask to mask the columns and <code>join</code> them:</p>
<pre><code>In [183]:
df['maxcol'] = df.ix[:,:'c'].eq(df['maxval'], axis=0).apply(lam... | 2 | 2016-07-06T12:04:15Z | [
"python",
"pandas"
] |
Return a pandas DataFrame when using pandas.DataFrame.mean | 38,223,574 | <p>The function <code>pandas.DataFrame.mean</code> always returns a <code>pandas.Series</code>. I would like it to return a dataframe with the same column names as the original dataframe. How does one do this? </p>
<pre><code>import numpy as np, pandas as pd
df = pd.DataFrame(np.random.rand(10,5), columns = ['a', '... | 1 | 2016-07-06T12:05:05Z | 38,223,596 | <p>You could do it like this using <code>to_frame</code> and transpose:</p>
<pre><code>In [188]:
df.mean().to_frame().T
Out[188]:
a b c d e
0 0.393221 0.441338 0.445528 0.67516 0.699105
</code></pre>
| 1 | 2016-07-06T12:06:27Z | [
"python",
"pandas",
"dataframe"
] |
How to convert a list of tuples into list of dictionaries with plus values? | 38,223,578 | <p>I have a list of tuples, e.g: <code>list_of_tuples = [('company_name', 56, 'green'), ('other_company', 43, 'blue')]</code></p>
<p>I have to convert this into a list of dictionaries in python. The key should be the company_name, and the values should be in a list, and I also have to add more values, like: <code>[{'c... | 0 | 2016-07-06T12:05:25Z | 38,223,602 | <p>You can use a list comprehension like so</p>
<pre><code>>>> [{i[0] : list(i[1:])} for i in list_of_tuples]
[{'company_name': [56, 'green']}, {'other_company': [43, 'blue']}]
</code></pre>
| 1 | 2016-07-06T12:06:36Z | [
"python"
] |
Filling NAN data with mode() doesn't work -Pandas | 38,223,579 | <p>I have a data set in which there is a series known as <code>Outlet_Size</code> which contain either of <code>{'Medium', nan, 'High', 'Small'}</code> around 2566 records are missing so I thought to fill it with mode() value so I wrote something like this :</p>
<pre><code> train['Outlet_Size']=train['Outlet_Size'].f... | 1 | 2016-07-06T12:05:25Z | 38,224,318 | <p>The problem here is that <code>mode</code> returns a series and this is causing the <code>fillna</code> to fail, if we look at a simple example:</p>
<pre><code>In [194]:
df = pd.DataFrame({'a':['low','low',np.NaN,'medium','medium','medium','medium']})
df
Out[194]:
a
0 low
1 low
2 NaN
3 med... | 1 | 2016-07-06T12:43:04Z | [
"python",
"pandas",
"machine-learning",
null
] |
python: How does subprocess.check_output create it's calls? | 38,223,625 | <p>I'm trying to read the duration of video files using mediainfo. This shell command works</p>
<pre><code>mediainfo --Inform="Video;%Duration/String3%" file
</code></pre>
<p>and produces an output like</p>
<pre><code>00:00:33.600
</code></pre>
<p>But when I try to run it in python with this line</p>
<pre><code>su... | 3 | 2016-07-06T12:08:14Z | 38,223,866 | <p>Try:</p>
<pre><code>subprocess.check_output(['mediainfo', '--Inform=Video;%Duration/String3%', file])
</code></pre>
<p>The <code>"</code> in your python string are likely passed on to <code>mediainfo</code>, which can't parse them and will ignore the option.</p>
<p>These kind of problems are often caused by shell... | 2 | 2016-07-06T12:20:25Z | [
"python",
"python-3.x",
"mediainfo"
] |
How to call Python function in Java | 38,223,631 | <p>This is my Python code:</p>
<pre><code>class myPythonClass:
def table(nb):
i = 0
while i < 10:
print(i + 1, "*", nb, "=", (i + 1) * nb)
i += 1
</code></pre>
<p>I need to know how to call it using PythonInterpreter.</p>
| -3 | 2016-07-06T12:08:26Z | 38,224,504 | <p>In Java use <a href="http://docs.oracle.com/javase/8/docs/api/java/lang/ProcessBuilder.html" rel="nofollow"><code>ProcessBuilder</code></a> to create a child process and capture its standard output. Here's an example:</p>
<pre><code>import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOE... | 0 | 2016-07-06T12:52:37Z | [
"java",
"python",
"spring"
] |
Difference between Matlab spectrogram and matplotlib specgram? | 38,223,687 | <p>I am trying to incorporate a preexisting spectrogram from Matlab into my python code, using Matplotlib. However, when I enter the window value, there is an issue: in Matlab, the value is a scalar, but Matplotlib requires a vector. Why is this so?</p>
| 1 | 2016-07-06T12:10:40Z | 38,223,850 | <p>The value in Matlab is a scalar as it represents the size of the window, and Matlab uses a Hamming window by default. The Window argument also accepts a vector, so you can pass in any windowing function you want.</p>
| 1 | 2016-07-06T12:19:31Z | [
"python",
"matlab",
"matplotlib",
"spectrogram"
] |
Difference between Matlab spectrogram and matplotlib specgram? | 38,223,687 | <p>I am trying to incorporate a preexisting spectrogram from Matlab into my python code, using Matplotlib. However, when I enter the window value, there is an issue: in Matlab, the value is a scalar, but Matplotlib requires a vector. Why is this so?</p>
| 1 | 2016-07-06T12:10:40Z | 38,225,574 | <p>The arguments are just organized differently.</p>
<p>In matplotlib, the window size is specified using the <code>NFFT</code> argument. The <code>window</code> argument, on the other hand, is <em>only</em> for specifying the window itself, rather than the size. So, like MATLAB, the <code>window</code> argument acce... | 1 | 2016-07-06T13:43:52Z | [
"python",
"matlab",
"matplotlib",
"spectrogram"
] |
Adding items from a text file to QlistWidget in pyQt5 | 38,223,705 | <p>I've been working on this code as part of my school project and i don't seem to be getting anywhere. My problem is when i try add the text from a file to my QlistWidget my program crashes. Firstly I want to know if this will add the files at the directory (each line in <code>movieDir.txt</code> is a directory) to th... | 1 | 2016-07-06T12:11:42Z | 38,235,665 | <pre><code> self.listWidget = QtWidgets.QListWidget(self.centralWidget)
self.listWidget.setObjectName("listWidget")
self.horizontalLayout_4.addWidget(self.listWidget)
with open('moviesDir.txt','r') as movieDir:
for movie in movieDir:
self.listWidget.addItem(movie)
</code></pre>
<p>T... | 0 | 2016-07-06T23:57:09Z | [
"python",
"pyqt",
"pyqt5"
] |
Adding items from a text file to QlistWidget in pyQt5 | 38,223,705 | <p>I've been working on this code as part of my school project and i don't seem to be getting anywhere. My problem is when i try add the text from a file to my QlistWidget my program crashes. Firstly I want to know if this will add the files at the directory (each line in <code>movieDir.txt</code> is a directory) to th... | 1 | 2016-07-06T12:11:42Z | 38,468,772 | <pre><code>#This is the example code for loading files and content inside the file to QtGui.QListWidget
#It is PyQt4, but you can try with PyQt5 with small changes.
#If your are not expecting this answer, sorry.
import sys, os
from PyQt4 import QtGui, QtCore
class Window (QtGui.QWidget):
def __init__(self, parent... | 0 | 2016-07-19T21:22:27Z | [
"python",
"pyqt",
"pyqt5"
] |
tensorflow 0.9 skflow model save and restore doesn't work | 38,223,839 | <p>I have updated my tensorflow from 0.7 to 0.9 on python3.And now i can't restore my previous saved models with skflow(tensorflow.contrib.learn).Here is the sample code example that was worked on tensorflow 0.7.</p>
<pre><code>import tensorflow.contrib.learn as skflow
from sklearn import datasets, metrics, preprocess... | 2 | 2016-07-06T12:18:58Z | 39,043,553 | <p>I belive save and restore have been deprecated in favor of the <code>model_dir</code> param when building the estimator/regressor :</p>
<pre><code>regressor = skflow.TensorFlowLinearRegressor(model_dir='/home/model/')
regressor.fit(X, boston.target)
...
estimator = skflow.TensorFlowLinearRegressor(model_dir='/home/... | 0 | 2016-08-19T16:11:43Z | [
"python",
"neural-network",
"tensorflow",
"skflow"
] |
SQL Count number of rows until reaches a specific value | 38,223,908 | <p>I'm doing a MySQL project where I need to retrieve how many <em>results/rows</em> are until the value is reached ordered by <code>points</code> row. </p>
<p>I did this, but it's a botched job code, and I guess I can improve it with a simple SQL using a <code>COUNT(value)</code> function. </p>
<pre><code>#Python
... | -2 | 2016-07-06T12:23:03Z | 38,223,988 | <p>Given you're able to get an id from nick, </p>
<pre><code>select count(1) from users where id < ?
</code></pre>
<p>where ? have to be substituted with user's id</p>
| 0 | 2016-07-06T12:27:32Z | [
"python",
"mysql"
] |
Python's multiprocessing returns more results than tasks where given | 38,223,910 | <p>I'm currently trying to use multiprocessing for my simulation run, to evaluate different input values at the same time.</p>
<p>Therefore, I googled a lot in the last weeks and got something together which is probably not very pretty but it (somehow) works. My Problem is now, that it returns more output than I have ... | 1 | 2016-07-06T12:23:05Z | 38,224,285 | <p>The way you assign the attributes to the class makes the attributes class attributes. That way they are shared between every instance of the class. In your case this doesn't appear immideatly because in every process you only have one instance of the class and the class object itself is not shared between processes.... | 1 | 2016-07-06T12:41:34Z | [
"python",
"multiprocessing",
"python-multiprocessing"
] |
Cartopy-Python syntax - multiple objects/countries in one line | 38,224,019 | <p>I'm following this example, <a href="http://gis.stackexchange.com/questions/88209/python-mapping-in-matplotlib-cartopy-color-one-country">Python Mapping in Matplotlib Cartopy Color One Country</a>. It's fully working with several countries, e.g. USA, France, UK, Japan.</p>
<pre><code>for country in countries:
i... | 1 | 2016-07-06T12:28:57Z | 38,274,249 | <p>You should use the <code>in</code> keyword, something like this:</p>
<pre class="lang-py prettyprint-override"><code>for country in countries:
if country.attributes['adm0_a3'] in ['USA', 'FRA', 'GBR', 'JPN']:
ax.add_geometries(country.geometry, ccrs.PlateCarree(),
facecolor=(0,... | 1 | 2016-07-08T19:40:12Z | [
"python",
"cartopy"
] |
generating a 8 character password including lower case and upper case and numbers using python | 38,224,105 | <p>i want generate password including lower case and upper case and numbers using python but it should guarantee that all these 3 kinds has been used. so far i wrote this but it does not guarantee that all 3 kinds of characters are being used. i want divide the 8 character to 2 part. first 3 and last 5. then make sure... | 2 | 2016-07-06T12:32:35Z | 38,224,245 | <p>Your question consists of 3 parts:</p>
<ol>
<li>divide the 8 character to 2 part - first 3 and last 5 - (string slicing)</li>
<li>make sure in the first part all 3 kinds of character are being used (validating passwords)</li>
<li>shuffle the characters (shuffling strings)</li>
</ol>
<hr>
<p><strong>Part1:</strong... | 0 | 2016-07-06T12:39:27Z | [
"python",
"password-generator"
] |
generating a 8 character password including lower case and upper case and numbers using python | 38,224,105 | <p>i want generate password including lower case and upper case and numbers using python but it should guarantee that all these 3 kinds has been used. so far i wrote this but it does not guarantee that all 3 kinds of characters are being used. i want divide the 8 character to 2 part. first 3 and last 5. then make sure... | 2 | 2016-07-06T12:32:35Z | 38,224,310 | <p>As you said: First three positions are randomly chosen from upper- and lowercase characters and digits, respectively, and the rest are randomly chosen from <em>all</em> characters, then shuffle.</p>
<pre><code>from random import choice, shuffle
from string import ascii_uppercase, ascii_lowercase, digits
pwd = [choi... | 3 | 2016-07-06T12:42:38Z | [
"python",
"password-generator"
] |
generating a 8 character password including lower case and upper case and numbers using python | 38,224,105 | <p>i want generate password including lower case and upper case and numbers using python but it should guarantee that all these 3 kinds has been used. so far i wrote this but it does not guarantee that all 3 kinds of characters are being used. i want divide the 8 character to 2 part. first 3 and last 5. then make sure... | 2 | 2016-07-06T12:32:35Z | 38,224,366 | <p>You could use regular expressions and check if any char matches the regular expression.</p>
<pre><code>import re
string = "AaBbCc12"
if re.search('[a-z]',string)\
and re.search('[0-9]',string)\
and re.search('[A-Z]',string):
print("This is a string you are looking for")
else:
print("Nope")
</code></pre>
... | 0 | 2016-07-06T12:45:15Z | [
"python",
"password-generator"
] |
Tkinter dynamically changing labels with a button and method | 38,224,180 | <p>I am working on a GUI using Tkinter. I am trying to dynamically update the contents of a message box. Below is my code </p>
<p>def makeDisplay():</p>
<pre><code>def updateEntry():
#phonelist[0]
v = StringVar()
v.set("additinalText")
def makeWindow() :
global v
win = Tk()
frame1 = Fra... | 2 | 2016-07-06T12:36:03Z | 38,224,657 | <p>First, you have to <em>create</em> <code>v</code> in <code>makeWindow</code>, and make it <code>global</code>:</p>
<pre><code>def makeWindow() :
global v
win = Tk()
v = StringVar()
</code></pre>
<p>Then, use it as the <code>textvariable</code> for the text field:</p>
<pre><code> msg = Message(fra... | 1 | 2016-07-06T12:59:40Z | [
"python",
"user-interface",
"tkinter"
] |
Python datetime comparison is incorrect in case of compare two time like: 12:00 and 11:59 | 38,224,199 | <p>so below example of code: </p>
<pre><code> >>> from datetime import datetime
>>> future = datetime.strptime('12:00', '%I:%M')
>>> past = datetime.strptime('11:59', '%I:%M')
>>> future < past
>>> True # expected False, because '12:00' > '11:59'
>>> pa... | 1 | 2016-07-06T12:36:58Z | 38,224,268 | <p>strptime in this case maps '12:00' to midnight ... the format specifier %I "means": "Hour (12-hour clock) as a zero-padded decimal number."</p>
| 0 | 2016-07-06T12:40:45Z | [
"python",
"datetime",
"datetime-comparison"
] |
Python datetime comparison is incorrect in case of compare two time like: 12:00 and 11:59 | 38,224,199 | <p>so below example of code: </p>
<pre><code> >>> from datetime import datetime
>>> future = datetime.strptime('12:00', '%I:%M')
>>> past = datetime.strptime('11:59', '%I:%M')
>>> future < past
>>> True # expected False, because '12:00' > '11:59'
>>> pa... | 1 | 2016-07-06T12:36:58Z | 38,224,280 | <p><code>%I</code> is the hours for a twelve hour clock. Unless you supply an AM or PM (<code>%p</code>), it takes the AM choice. 12:00 AM (i.e. midnight) is before 11:59 AM.</p>
<p>If you use <code>%H</code> you get 24 hour clock, in which 12:00 will be noon instead of midnight.</p>
<p><a href="https://docs.python.o... | 3 | 2016-07-06T12:41:24Z | [
"python",
"datetime",
"datetime-comparison"
] |
Python datetime comparison is incorrect in case of compare two time like: 12:00 and 11:59 | 38,224,199 | <p>so below example of code: </p>
<pre><code> >>> from datetime import datetime
>>> future = datetime.strptime('12:00', '%I:%M')
>>> past = datetime.strptime('11:59', '%I:%M')
>>> future < past
>>> True # expected False, because '12:00' > '11:59'
>>> pa... | 1 | 2016-07-06T12:36:58Z | 38,224,389 | <p>The issue here is <em>which</em> <code>12:00</code> you mean. Printing out the datetimes in question might help you to understand:</p>
<pre><code>future, past, past_2
</code></pre>
<p>has the value:</p>
<pre><code>(datetime.datetime(1900, 1, 1, 0, 0),
datetime.datetime(1900, 1, 1, 11, 59),
datetime.datetime(190... | 0 | 2016-07-06T12:46:37Z | [
"python",
"datetime",
"datetime-comparison"
] |
Pandas series operator as function parameter | 38,224,254 | <h2>Background</h2>
<p>I want to perform a calculation on a Pandas Series. This calculation involves <code>min</code> and <code>max</code>. The calculation is used twice. In both cases it is the same calculation except for the <code>min</code> or <code>max</code> functions, which should be different.</p>
<p>I've crea... | 0 | 2016-07-06T12:39:53Z | 38,224,336 | <p>There's really no pretty way to do it.</p>
<pre><code>def my_calc(my_series, func=max):
if not func in {'min', 'max'}:
raise ValueError('{} is not a valid method name!'.format(func))
return getattr(my_series.rolling(...), func)()
foo = my_calc(some_series, 'min')
bar = my_calc(some_series, 'max')
</cod... | 1 | 2016-07-06T12:43:49Z | [
"python",
"pandas"
] |
Pandas series operator as function parameter | 38,224,254 | <h2>Background</h2>
<p>I want to perform a calculation on a Pandas Series. This calculation involves <code>min</code> and <code>max</code>. The calculation is used twice. In both cases it is the same calculation except for the <code>min</code> or <code>max</code> functions, which should be different.</p>
<p>I've crea... | 0 | 2016-07-06T12:39:53Z | 38,224,398 | <p>Call <code>my_calc</code> with the name of the function as string, then use <code>getattr</code>:</p>
<pre><code>def my_calc(my_series, func_name):
try:
return getattr(my_series.rolling(...), func_name)()
except AttributeError:
print('{} has no attribute {}'.format(type(my_series), func_name... | 1 | 2016-07-06T12:46:56Z | [
"python",
"pandas"
] |
Pandas series operator as function parameter | 38,224,254 | <h2>Background</h2>
<p>I want to perform a calculation on a Pandas Series. This calculation involves <code>min</code> and <code>max</code>. The calculation is used twice. In both cases it is the same calculation except for the <code>min</code> or <code>max</code> functions, which should be different.</p>
<p>I've crea... | 0 | 2016-07-06T12:39:53Z | 38,224,408 | <p>Try like this <code>rolling_max</code> </p>
<pre><code>def my_calc(my_series):
return my_series.rolling_max(...)
</code></pre>
| 1 | 2016-07-06T12:47:18Z | [
"python",
"pandas"
] |
Pandas series operator as function parameter | 38,224,254 | <h2>Background</h2>
<p>I want to perform a calculation on a Pandas Series. This calculation involves <code>min</code> and <code>max</code>. The calculation is used twice. In both cases it is the same calculation except for the <code>min</code> or <code>max</code> functions, which should be different.</p>
<p>I've crea... | 0 | 2016-07-06T12:39:53Z | 38,224,542 | <p>You can use apply (or agg):</p>
<pre><code>def my_calc(my_series, func):
return my_series.rolling(...).apply(func)
</code></pre>
<p>And use like:</p>
<pre><code>my_calc(ser, np.mean)
Out[321]:
0 NaN
1 0.5
2 0.0
3 0.5
4 2.0
Name: a, dtype: float64
</code></pre>
| 1 | 2016-07-06T12:54:28Z | [
"python",
"pandas"
] |
ToUnicodeEx() always returns 0 in python | 38,224,277 | <p>I was trying to wrap C++ function ToUnicodeEx() in python, but it not works correctly, always returns 0.<br/>
On MSDN 0 means:<br/></p>
<blockquote>
<p>The specified virtual key has no translation for the current state of the keyboard. Nothing was written to the buffer specified by pwszBuff.</p>
</blockquote>
<p... | -1 | 2016-07-06T12:41:18Z | 38,231,231 | <p>This more closely matches the MSDN documentation for ToUnicodeEx:</p>
<pre><code>_ToUnicodeEx.argtypes = [c_uint,c_uint,POINTER(c_char),POINTER(c_wchar),c_int,c_uint,c_void_p]
</code></pre>
<p><code>c_wchar_p</code> assumes null termination and <code>c_void_p</code> is appropriate for a handle. The third paramete... | 2 | 2016-07-06T18:29:36Z | [
"python",
"winapi",
"ctypes",
"user32"
] |
Choosing randomly between two possibilities | 38,224,326 | <p>I have the following file:</p>
<pre><code>452 0/0 10 30 40
460 0/1 0 40 40
500 0/0 5 35 40
600 0/1 15 25 40
800 1/1 40 0 40
</code></pre>
<p>The real file contains millions of lines. If the second field is 0/0, I print the 3rd and 5th columns. If the second field is 1/1, I print the 4th and 5th columns. Using thi... | 0 | 2016-07-06T12:43:20Z | 38,224,481 | <p>Using the <a href="http://stackoverflow.com/a/4048538/1983854">Random numbers generation with awk in BASH shell</a> trick by paxdiablo, you can say:</p>
<pre><code>awk -v seed=$RANDOM 'BEGIN {srand(seed)}
$2=="0/0" {chosen=3}
$2=="1/1" {chosen=4}
$2=="0/1" {chosen=3+int(rand()+0.5)}
... | 2 | 2016-07-06T12:51:37Z | [
"python",
"bash",
"random",
"awk"
] |
Choosing randomly between two possibilities | 38,224,326 | <p>I have the following file:</p>
<pre><code>452 0/0 10 30 40
460 0/1 0 40 40
500 0/0 5 35 40
600 0/1 15 25 40
800 1/1 40 0 40
</code></pre>
<p>The real file contains millions of lines. If the second field is 0/0, I print the 3rd and 5th columns. If the second field is 1/1, I print the 4th and 5th columns. Using thi... | 0 | 2016-07-06T12:43:20Z | 38,224,537 | <p>A solution using python: you could use <code>random</code> and point to a list containing <code>0</code> and <code>1</code></p>
<pre><code>import random
binaryChoice = ['0','1']
field = ('0/1')
if field == ('0/1'):
choice = random.choice(binaryChoice)
print (choice)
</code></pre>
| 0 | 2016-07-06T12:54:16Z | [
"python",
"bash",
"random",
"awk"
] |
Searching bing results with a script results in an encoding issue | 38,224,373 | <p>I've written the following in order to get number of search results per word in my <code>wordlist</code>:</p>
<pre><code>with open ("C:\wordslist.txt") as f:
lines = f.readlines()
def bingSearch(word):
r = requests.get('http://www.bing.com/search',
params={'q':'"'+word+'"'}
... | 0 | 2016-07-06T12:45:40Z | 38,224,799 | <p>try giving the encoding directly when you open your file, it can make the difference</p>
<p><code>with open ("C:\wordslist.txt", encoding="utf-8") as f:</code></p>
<p><a href="https://docs.python.org/3/library/functions.html#open" rel="nofollow">https://docs.python.org/3/library/functions.html#open</a></p>
| 2 | 2016-07-06T13:05:56Z | [
"python",
"python-3.x",
"character-encoding",
"bing"
] |
Unable to load patterns in AIML via Python | 38,224,450 | <p>I've installed AIML via pip and wrote files <em>startup.py</em>, <em>std-startup.xml</em>, <em>basic.aiml</em> and <em>bot_brain.brn</em> in <strong>core</strong> folder. When I try to run <em>startup.py</em>, I get this warning:</p>
<pre><code>Loading std-startup.xml... done (0.06 seconds)
WARNING: No match found ... | 0 | 2016-07-06T12:49:47Z | 38,225,177 | <p>Problem is solved; I had to enter it with uppercase letters:</p>
<pre><code><category>
<pattern>LOAD AIML B</pattern>
<template>
<learn>basic.aiml</learn>
</template>
</category>
</code></pre>
| 0 | 2016-07-06T13:23:47Z | [
"python",
"aiml"
] |
Using a python method in a class to check variables are the same in another class object | 38,224,454 | <p>I have 2 files which I am using python class methods to parse data from and create sql INSERT statements. In both of my files I have a list of gene names. The first file is a simple list of 20 gene names with a panel name that is always the same. The second file has more information about the genes, and there will b... | 0 | 2016-07-06T12:49:58Z | 38,224,946 | <p>class Variants(Gene):</p>
<pre><code>def __init__(self, gene, run_id, sample, variant):
self.run_id = run_id
self.sample = sample
self.gene = gene.gene
self.variant = variant
def check_gene(gene):
if self.gene not in gene.gene:
print('Gene not correct')
</code></pre>
| 0 | 2016-07-06T13:12:06Z | [
"python",
"python-2.7",
"class",
"inheritance",
"methods"
] |
Using a python method in a class to check variables are the same in another class object | 38,224,454 | <p>I have 2 files which I am using python class methods to parse data from and create sql INSERT statements. In both of my files I have a list of gene names. The first file is a simple list of 20 gene names with a panel name that is always the same. The second file has more information about the genes, and there will b... | 0 | 2016-07-06T12:49:58Z | 38,225,235 | <p>I don't think inheritance can help you with this one. You can try to make a class variable for all <code>Gene</code>:</p>
<pre><code>class Gene(object):
# The class variable that keeps track of all genes
genes = []
def __init__(self, gene):
Gene.genes.append(gene)
self.gene = gene
<... | 0 | 2016-07-06T13:26:56Z | [
"python",
"python-2.7",
"class",
"inheritance",
"methods"
] |
Remove decimal points and commas using regex in python | 38,224,480 | <p>I have the following string:</p>
<pre><code>st='19.000\n20,000'
</code></pre>
<p>i want to remove the commas and points <strong>ONLY FOR NUMBERS</strong>. I am using the following code</p>
<pre><code>re.sub(r'[^\d\.]','',st)
</code></pre>
<p>The result is:</p>
<blockquote>
<p>'19.00020000'</p>
</blockquote>
... | -1 | 2016-07-06T12:51:27Z | 38,224,562 | <p><code>[^\d\.]</code>, since it starts with a <code>^</code>, matches everything that <em>isn't</em> a digit (<code>\d</code>) or point (<code>\.</code>). If you want to remove commas and points, you want to match <code>,</code> or <code>\.</code>, which can be written <code>[,\.]</code> or <code>[\.,]</code>. In <... | 1 | 2016-07-06T12:55:21Z | [
"python",
"regex"
] |
Remove decimal points and commas using regex in python | 38,224,480 | <p>I have the following string:</p>
<pre><code>st='19.000\n20,000'
</code></pre>
<p>i want to remove the commas and points <strong>ONLY FOR NUMBERS</strong>. I am using the following code</p>
<pre><code>re.sub(r'[^\d\.]','',st)
</code></pre>
<p>The result is:</p>
<blockquote>
<p>'19.00020000'</p>
</blockquote>
... | -1 | 2016-07-06T12:51:27Z | 38,224,670 | <p><code>^\d</code> matches everything that is not a digit.</p>
<p>Instead, you should use <code>(?<=\d)[,\.]</code>.</p>
<p><code>(?<=\d)</code> ensures that there are digits before the comma or the point.</p>
<pre><code>import re
st = '19.000\n20,000\na.a,a'
print(re.sub(r'(?<=\d)[,\.]','',st))
>>... | 4 | 2016-07-06T13:00:20Z | [
"python",
"regex"
] |
Way of removing a kivy attribute? | 38,224,495 | <p>I'm using the following class template, which has the benefits of making the buttons flat, and removing the grey tint so that they appear brighter:</p>
<pre><code><Button>:
background_normal: ''
</code></pre>
<p>I'd like an option to change this at runtime (revert to 'original theme', if you like), so I ... | 0 | 2016-07-06T12:52:09Z | 38,225,395 | <p><code>background_normal</code> is a string property which defaults to <code>'atlas://data/images/defaulttheme/button'</code>. If you set it to the string <code>''</code> it will be "deactivated". If you want to set it back you can set it to the default again.</p>
<p>Here is the appropriate <a href="https://kivy.org... | 1 | 2016-07-06T13:35:54Z | [
"python",
"kivy"
] |
Merge a lot of df using pandas | 38,224,531 | <p>I have a big df and use 'chunksize' to divide it.
after that that I use loop to go through the interval of df and next loop to do some condition and next I want to merge all of this df. I try 'concat(df)' but it return error. method 'join' is not convenient because I have 400 df.
how can I concatenate this?
This ... | 0 | 2016-07-06T12:53:45Z | 38,224,844 | <p>The pandas v0.18.1 documentation <a href="http://pandas.pydata.org/pandas-docs/stable/merging.html" rel="nofollow">Merge, join, and concatenate</a> states a list of dataframes as argument / parameter to the concat function as sample:</p>
<pre><code>import pandas as pd
# ... generate df1 et al.
frames = [df1, df2, d... | 0 | 2016-07-06T13:07:30Z | [
"python",
"pandas"
] |
Chain together methods in Python as in Ruby | 38,224,573 | <p>In Ruby, one can chain together methods like so:</p>
<pre><code>a = [2,3,1]
b = a.sort.reverse
</code></pre>
<p>which sets the value of the variable <code>b</code> to <code>[3,2,1]</code> while leaving <code>a</code> the same.</p>
<p>I'd like to perform similar operations in Python. So far, the shortest way to do... | 4 | 2016-07-06T12:55:41Z | 38,224,666 | <p>Clarification: The original answer is found below. As commented, the question is on chaining <em>in general</em>, not in any specific case. A clarification on this can be found at the end of this answer.</p>
<hr>
<p>You can write this down pretty much directly.</p>
<pre><code>a = [2,3,1]
b = sorted(a, reverse=Tru... | 4 | 2016-07-06T13:00:11Z | [
"python",
"ruby"
] |
Chain together methods in Python as in Ruby | 38,224,573 | <p>In Ruby, one can chain together methods like so:</p>
<pre><code>a = [2,3,1]
b = a.sort.reverse
</code></pre>
<p>which sets the value of the variable <code>b</code> to <code>[3,2,1]</code> while leaving <code>a</code> the same.</p>
<p>I'd like to perform similar operations in Python. So far, the shortest way to do... | 4 | 2016-07-06T12:55:41Z | 38,226,290 | <p>To chain methods I can suggest the following. May not be considered good pythonianship, though :-). </p>
<pre><code>a = [2,3,1]
[eval('a.'+f+'()') for f in ['sort', 'reverse']]
</code></pre>
<p>Note that this has nothing to do with the methods working on the original object and not on a copy.</p>
| 0 | 2016-07-06T14:16:21Z | [
"python",
"ruby"
] |
Best practice to "transport" trained model from sklearn | 38,224,639 | <pre><code>import matplotlib.pyplot as plt
import numpy as np
from sklearn import datasets, linear_model
# Create linear regression object
regr = linear_model.LinearRegression()
# Train the model using the training sets
regr.fit(X_train, y_train)
# how save ?????
# save here
</code></pre>
<p>What the <strong>best p... | 1 | 2016-07-06T12:58:44Z | 38,224,760 | <p><code>sklearn</code> has a <code>joblib</code> module for persisting models and/or saving to a file:</p>
<pre><code>from sklearn.externals import joblib
joblib.dump(regr, 'file_name.pkl')
# load pickled model later
regr = joblib.load('file_name.pkl')
</code></pre>
<p>You can also use Python's builtin <code>pick... | 2 | 2016-07-06T13:04:35Z | [
"python",
"python-2.7",
"machine-learning",
"sklearn-pandas"
] |
Spotfire: "limit data using markings" by python script | 38,224,691 | <p>Is there a way to check or uncheck certain markings in "limit data using markings" in a visualization through a python script?</p>
| 0 | 2016-07-06T13:01:17Z | 38,240,150 | <p>The answer from <a href="https://community.tibco.com/questions/limit-data-using-markings-python-script" rel="nofollow">https://community.tibco.com/questions/limit-data-using-markings-python-script</a></p>
<pre><code>from Spotfire.Dxp import Data
from Spotfire.Dxp.Application.Visuals import *
vis.As[VisualContent](... | 0 | 2016-07-07T07:48:42Z | [
"python",
"spotfire"
] |
why dict does not have remove method? | 38,224,742 | <p>I know python list has a remove() method, which remove the given object from the list.</p>
<pre><code>aList = [123, 'xyz', 'zara', 'abc', 'xyz']
aList.remove('xyz')
</code></pre>
<p>I know that we can use del statement to delete an item from the list by offset: </p>
<pre><code>del aList[-1]
</code></pre>
<p>I al... | 4 | 2016-07-06T13:03:32Z | 38,224,759 | <p>It does, it's just called <a href="https://docs.python.org/3/library/stdtypes.html#dict.pop" rel="nofollow"><code>pop</code></a>:</p>
<blockquote>
<p>pop(key[, default])<br>
If key is in the dictionary, remove it and return its value, else return default. If default is not given and key is not in the dictionary... | 3 | 2016-07-06T13:04:30Z | [
"python"
] |
why dict does not have remove method? | 38,224,742 | <p>I know python list has a remove() method, which remove the given object from the list.</p>
<pre><code>aList = [123, 'xyz', 'zara', 'abc', 'xyz']
aList.remove('xyz')
</code></pre>
<p>I know that we can use del statement to delete an item from the list by offset: </p>
<pre><code>del aList[-1]
</code></pre>
<p>I al... | 4 | 2016-07-06T13:03:32Z | 38,224,990 | <p>If you look at this question: <a href="http://stackoverflow.com/questions/11520492/difference-between-del-remove-and-pop-on-lists">Difference between del, remove and pop on lists</a> : you'll note the main answer points out</p>
<blockquote>
<p>remove: removes the <em>first</em> matching <em>value</em>, not a spec... | 4 | 2016-07-06T13:14:22Z | [
"python"
] |
why dict does not have remove method? | 38,224,742 | <p>I know python list has a remove() method, which remove the given object from the list.</p>
<pre><code>aList = [123, 'xyz', 'zara', 'abc', 'xyz']
aList.remove('xyz')
</code></pre>
<p>I know that we can use del statement to delete an item from the list by offset: </p>
<pre><code>del aList[-1]
</code></pre>
<p>I al... | 4 | 2016-07-06T13:03:32Z | 38,225,064 | <p>Note that <code>list.remove</code> makes a very strict guarantee - removing the <strong>first</strong> occurrence of a <em>value</em>. Now, the ordering in a <code>dict</code> is arbitrary - there is no "first".</p>
| 4 | 2016-07-06T13:17:51Z | [
"python"
] |
why dict does not have remove method? | 38,224,742 | <p>I know python list has a remove() method, which remove the given object from the list.</p>
<pre><code>aList = [123, 'xyz', 'zara', 'abc', 'xyz']
aList.remove('xyz')
</code></pre>
<p>I know that we can use del statement to delete an item from the list by offset: </p>
<pre><code>del aList[-1]
</code></pre>
<p>I al... | 4 | 2016-07-06T13:03:32Z | 39,028,147 | <p>Dictionaries have <code>pop</code>, but not <code>remove</code>. Why not? Because <code>remove</code> finds the <em>first</em> matching <em>value</em> and removes it, and returns nothing. So in a dictionary:</p>
<pre><code>{'a': 5, 'b': 5}
</code></pre>
<p><code>dict.remove</code> ought to remove <em>values</em>. ... | 1 | 2016-08-18T22:00:23Z | [
"python"
] |
Slicing sublists with different lengths | 38,224,821 | <p>I have a list of lists. Each sublist has a length that varies between 1 and 100. Each sublist contains a particle ID at different times in a set of data. I would like to form lists of all particle IDs at a given time. To do this I could use something like:</p>
<pre><code> list = [[1,2,3,4,5],[2,6,7,8],[1,3,6,7,8... | 4 | 2016-07-06T13:06:37Z | 38,225,019 | <pre><code>lst = [[1,2,3,4,5],[2,6,7,8],[1,3,6,7,8]]
func = lambda x: [line[x] for line in lst if len(line) > x]
func(3)
[4, 8, 7]
func(4)
[5, 8]
</code></pre>
<p>--update--</p>
<pre><code>func = lambda x: [ (line[x],i) for i,line in enumerate(lst) if len(line) > x]
func(4)
[(5, 0), (8, 2)]
</code></pre>
| 2 | 2016-07-06T13:15:31Z | [
"python",
"list",
"numpy",
"slice"
] |
Slicing sublists with different lengths | 38,224,821 | <p>I have a list of lists. Each sublist has a length that varies between 1 and 100. Each sublist contains a particle ID at different times in a set of data. I would like to form lists of all particle IDs at a given time. To do this I could use something like:</p>
<pre><code> list = [[1,2,3,4,5],[2,6,7,8],[1,3,6,7,8... | 4 | 2016-07-06T13:06:37Z | 38,225,143 | <p>If you want it with a <code>one-line forloop</code> and in an <code>array</code> you can do this:</p>
<pre><code>list2 = [[item[i] for item in list if len(item) > i] for i in range(0, 100)]
</code></pre>
<p>And if you want to know which id is from which list you can do this:</p>
<pre><code>list2 = [{list.index... | 0 | 2016-07-06T13:22:00Z | [
"python",
"list",
"numpy",
"slice"
] |
Slicing sublists with different lengths | 38,224,821 | <p>I have a list of lists. Each sublist has a length that varies between 1 and 100. Each sublist contains a particle ID at different times in a set of data. I would like to form lists of all particle IDs at a given time. To do this I could use something like:</p>
<pre><code> list = [[1,2,3,4,5],[2,6,7,8],[1,3,6,7,8... | 4 | 2016-07-06T13:06:37Z | 38,225,313 | <p>You could append <code>numpy.nan</code> to your short lists and afterwards create a numpy array</p>
<pre><code>import numpy
import itertools
lst = [[1,2,3,4,5],[2,6,7,8],[1,3,6,7,8,9]]
arr = numpy.array(list(itertools.izip_longest(*lst, fillvalue=numpy.nan)))
</code></pre>
<p>Afterwards you can use numpy slicing ... | 0 | 2016-07-06T13:31:57Z | [
"python",
"list",
"numpy",
"slice"
] |
Slicing sublists with different lengths | 38,224,821 | <p>I have a list of lists. Each sublist has a length that varies between 1 and 100. Each sublist contains a particle ID at different times in a set of data. I would like to form lists of all particle IDs at a given time. To do this I could use something like:</p>
<pre><code> list = [[1,2,3,4,5],[2,6,7,8],[1,3,6,7,8... | 4 | 2016-07-06T13:06:37Z | 38,225,334 | <p>You could use <a href="https://docs.python.org/3/library/itertools.html#itertools.zip_longest" rel="nofollow"><code>itertools.zip_longest</code></a>. This will <code>zip</code> the lists together and insert <code>None</code> when one of the lists is exhausted.</p>
<pre><code>>>> lst = [[1,2,3,4,5],['A','B'... | 0 | 2016-07-06T13:33:14Z | [
"python",
"list",
"numpy",
"slice"
] |
Slicing sublists with different lengths | 38,224,821 | <p>I have a list of lists. Each sublist has a length that varies between 1 and 100. Each sublist contains a particle ID at different times in a set of data. I would like to form lists of all particle IDs at a given time. To do this I could use something like:</p>
<pre><code> list = [[1,2,3,4,5],[2,6,7,8],[1,3,6,7,8... | 4 | 2016-07-06T13:06:37Z | 38,225,542 | <p><strong>Approach #1</strong></p>
<p>One almost* vectorized approach could be suggested that goes along creating ID based on the new order and splitting, like so -</p>
<pre><code>def position_based_slice(L):
# Get lengths of each element in input list
lens = np.array([len(item) for item in L])
# Form ... | 0 | 2016-07-06T13:42:14Z | [
"python",
"list",
"numpy",
"slice"
] |
python SOMETIMES os.environ has no pythonpath | 38,224,900 | <p>if i run the following script in Aptana Studio 3:</p>
<pre><code>import os
from pprint import pprint
pprint(os.environ['PYTHONPATH'].split(os.pathsep))
</code></pre>
<p>I get the following output:</p>
<pre><code>['C:\\Users\\Phocas_Tommy\\plugins\\org.python.pydev_3.0.0.1388187472\\pysrc\\pydev_sitecustomize',
'... | 1 | 2016-07-06T13:09:57Z | 38,225,187 | <p>PYTHONPATH is an environment variable. How are you starting Sublime Text 3? Why do you think the environment in which it runs should have a PYTHONPATH setting? Can you run Sublime Text from the command line? </p>
<p>The bottom line is that Sublime Text does not appear to be running in the same environment as it is ... | 1 | 2016-07-06T13:24:05Z | [
"python",
"operating-system",
"sublimetext3",
"aptana",
"pythonpath"
] |
How to use the IE webdriver from selenium for python (Failed to navigate error)? | 38,224,983 | <p>I am trying to use the python-selenium API (version 2.53.6) to perform GUI tests on different browsers. When I try to use IE (11.0.10240) in the following way (Windows Server 2012 R2 Standard, 64bit); using authentication:</p>
<pre><code>driver = webdriver.Ie()
driver.get("http://user:password@my.test.server.com")
... | 11 | 2016-07-06T13:13:59Z | 38,273,004 | <p>Not directly answering the question, but I could not reproduce it when using IE11 on Windows 10 through BrowserStack and opening <a href="http://@www.httpwatch.com/httpgallery/authentication/authenticatedimage/default.aspx?0.7349707232788205" rel="nofollow">this http auth protected page</a>:</p>
<pre><code>from sel... | 1 | 2016-07-08T18:12:05Z | [
"python",
"internet-explorer",
"selenium",
"selenium-webdriver"
] |
How to use the IE webdriver from selenium for python (Failed to navigate error)? | 38,224,983 | <p>I am trying to use the python-selenium API (version 2.53.6) to perform GUI tests on different browsers. When I try to use IE (11.0.10240) in the following way (Windows Server 2012 R2 Standard, 64bit); using authentication:</p>
<pre><code>driver = webdriver.Ie()
driver.get("http://user:password@my.test.server.com")
... | 11 | 2016-07-06T13:13:59Z | 38,390,435 | <p>Have you tried using it this way ?</p>
<blockquote>
<p>driver.current_url("<a href="http://user:password@my.test.server.com" rel="nofollow">http://user:password@my.test.server.com</a>")</p>
</blockquote>
| 0 | 2016-07-15T07:36:16Z | [
"python",
"internet-explorer",
"selenium",
"selenium-webdriver"
] |
Scale rows of 3D-tensor | 38,224,985 | <p>I have an <code>n</code>-by-<code>3</code>-by-<code>3</code> numpy array <code>A</code> and an <code>n</code>-by-<code>3</code> numpy array <code>B</code>. I'd now like to multiply every <em>row</em> of every one of the <code>n</code> <code>3</code>-by-<code>3</code> matrices with the corresponding scalar in <code>B... | 0 | 2016-07-06T13:14:09Z | 38,226,914 | <p>You can use <a href="http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html" rel="nofollow"><code>NumPy broadcasting</code></a> to let the elementwise multiplication happen in a vectorized manner after extending <code>B</code> to <code>3D</code> after adding a singleton dimension at the end with <code>np.newa... | 1 | 2016-07-06T14:43:37Z | [
"python",
"arrays",
"numpy",
"matrix"
] |
Run IPython by default and show at startup in Eclipse PyDev | 38,225,005 | <p>As there were no satisfying answers in the following links </p>
<p><a href="http://stackoverflow.com/questions/13997877/set-default-directory-of-pydev-interactive-console">Set default directory of Pydev interactive console?</a></p>
<p><a href="http://stackoverflow.com/questions/10732856/pydev-startup">Pydev - star... | 0 | 2016-07-06T13:15:14Z | 38,226,675 | <p>Well, there's no feature to open it at startup by default, but you can do Ctrl+Alt+Enter to first open it and after it's opened, do <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>Enter</kbd> again to execute the current file in that console... </p>
<p>Alternatively, you may also use <kbd>F2</kbd> to send the current line to t... | 0 | 2016-07-06T14:32:40Z | [
"python",
"eclipse",
"pydev"
] |
Python M2Crypto load_pub_key from string | 38,225,131 | <p>How i can load_pub_key from string.</p>
<pre><code>pub_key1 = M2Crypto.RSA.load_pub_key('public.pem')
f = open('public.pem', 'rb')
bio = M2Crypto.BIO.MemoryBuffer(f.read())
pub_key2 = M2Crypto.RSA.load_pub_key_bio(bio)
print pub_key1 == pub_key2
false
</code></pre>
| 1 | 2016-07-06T13:21:27Z | 38,243,585 | <p>print pub_key1 == pub_key2 -> false, but:</p>
<pre><code>PUBKEY_TEMPLATE = "-----BEGIN PUBLIC KEY-----\n{}\n-----END PUBLIC KEY-----"
pub_key1 = M2Crypto.RSA.load_pub_key('public.pem')
bio = M2Crypto.BIO.MemoryBuffer(PUBKEY_TEMPLATE.format('<string with pub key>'.strip()))
pub_key2 = M2Crypto.RSA.load_pub_key... | 1 | 2016-07-07T10:51:02Z | [
"python",
"m2crypto"
] |
argparse - Different mandatory / available parameters per action | 38,225,164 | <p>I'm looking to create an argument parser with the following structure:</p>
<pre><code>options [ 'backup', 'consistency_check', 'backup_and_consistency_check']
--database [ required ]
--action [ required choice from list options ]
--where_to_backup_to [ only required if --action is 'backup' ]
--what_file_to_con... | 2 | 2016-07-06T13:22:52Z | 38,226,261 | <p>I think making action a positional parameter with dynamic option parser is a good option:</p>
<pre><code>if __name__ == "__main__":
action = sys.argv[1]
parser = create_parser(action)
args = parser.parse_args()
</code></pre>
| 2 | 2016-07-06T14:15:01Z | [
"python",
"arguments",
"command-line-arguments",
"argparse"
] |
argparse - Different mandatory / available parameters per action | 38,225,164 | <p>I'm looking to create an argument parser with the following structure:</p>
<pre><code>options [ 'backup', 'consistency_check', 'backup_and_consistency_check']
--database [ required ]
--action [ required choice from list options ]
--where_to_backup_to [ only required if --action is 'backup' ]
--what_file_to_con... | 2 | 2016-07-06T13:22:52Z | 38,226,320 | <p>The conventional way to do this would look more like the following:</p>
<pre><code>def create_parser():
parser = ArgumentParser(description='Parser for Backup / Consistency Check')
parser.add_argument('--database', '-d', dest='db', help='Database name', choices=get_active_database_list())
parser.add_ar... | 2 | 2016-07-06T14:17:34Z | [
"python",
"arguments",
"command-line-arguments",
"argparse"
] |
argparse - Different mandatory / available parameters per action | 38,225,164 | <p>I'm looking to create an argument parser with the following structure:</p>
<pre><code>options [ 'backup', 'consistency_check', 'backup_and_consistency_check']
--database [ required ]
--action [ required choice from list options ]
--where_to_backup_to [ only required if --action is 'backup' ]
--what_file_to_con... | 2 | 2016-07-06T13:22:52Z | 38,228,737 | <p>If subparsers seem too complex at the moment, I think you can still get a useful parser without them:</p>
<pre><code>def create_parser():
parser = ArgumentParser(description='Parser for Backup / Consistency Check')
parser.add_argument('--database', '-d', dest='db', help='Database name', choices=get_active_... | 2 | 2016-07-06T16:13:18Z | [
"python",
"arguments",
"command-line-arguments",
"argparse"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.