qid
int64
46k
74.7M
question
stringlengths
54
37.8k
date
stringlengths
10
10
metadata
listlengths
3
3
response_j
stringlengths
17
26k
response_k
stringlengths
26
26k
55,494,430
Plz suggest how to create dictionary from the following file contetns ``` 2,20190327.1.csv.gz 3,20190327.23.csv.gz 4,20190327.21302.csv.gz 2,20190327.24562.csv.gz ``` my required output is ``` {2:20190327.1.csv.gz:982, 3:20190327.23.csv.gz, 4:20190327.21302.csv.gz, 2:20190327.24562.csv.gz} ``` I am new to python...
2019/04/03
[ "https://Stackoverflow.com/questions/55494430", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3619226/" ]
You could use `$"color".isin("GREEN","RED","YELLOW")` Code example: ``` val df2 = df.withColumn("Ind", when($"color".isin("GREEN","RED","YELLOW"), 1).otherwise(0)) df2.show(false) ``` Outputs: ``` +------+---+ | color|Ind| +------+---+ | RED| 1| | GREEN| 1| |YELLOW| 1| | PINK| 0| +------+---+ ``` A quic...
You should be able to check the column against a list with: ``` val result = df.withColumn("Ind", when($"color".in("GREEN", "RED", "YELLOW"), 1).otherwise(0)) ```
3,902,608
I'm pretty new to python and am trying to grab the ropes and decided a fun way to learn would be to make a cheesy MUD type game. My goal for the piece of code I'm going to show is to have three randomly selected enemies(from a list) be presented for the "hero" to fight. The issue I am running into is that python is cop...
2010/10/10
[ "https://Stackoverflow.com/questions/3902608", "https://Stackoverflow.com", "https://Stackoverflow.com/users/471561/" ]
Change ``` genENE.insert(i,enemies[0]) ``` to ``` genENE.insert(i,enemies[0][:]) ``` This will force the list to be copied rather than referenced. Also, I would use append rather than insert in this instance.
`they all subtract that value` What do you mean do they all? If you mean both lists, you're problem is because you're only referencing the list NOT creating a second one.
58,931,845
My Airflow DAGs mainly consist of PythonOperators, and I would like to use my Python IDEs debug tools to develop python "inside" airflow. - I rely on Airflow's database connectors, which I think would be ugly to move "out" of airflow for development. I have been using Airflow for a bit, and have so far only achieved d...
2019/11/19
[ "https://Stackoverflow.com/questions/58931845", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5152989/" ]
It might be somewhat of a hack, but I found one way to set up PyCharm: * Use `which airflow` to the local airflow environment - which in my case is just a pipenv * Add a new run configuration in PyCharm * Set the python "Script path" to said airflow script * Set Parameters to test a task: `test dag_x task_y 2019-11-19...
I debug `airflow test dag_id task_id`, run on a vagrant machine, using PyCharm. You should be able to use the same method, even if you're running airflow directly on localhost. [Pycharm's documentation on this subject](https://www.jetbrains.com/help/pycharm/remote-debugging-with-product.html#remote-debug-config) shoul...
58,931,845
My Airflow DAGs mainly consist of PythonOperators, and I would like to use my Python IDEs debug tools to develop python "inside" airflow. - I rely on Airflow's database connectors, which I think would be ugly to move "out" of airflow for development. I have been using Airflow for a bit, and have so far only achieved d...
2019/11/19
[ "https://Stackoverflow.com/questions/58931845", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5152989/" ]
Might be a little late to the party, but been looking for a solution to this as well. Wanted to be able to debug code as close to "production mode" as possible (so nothing with test etc). Found a solution in the form of the "Python Debug Server". It works the other way around: Your IDE listens and the connection is ma...
It might be somewhat of a hack, but I found one way to set up PyCharm: * Use `which airflow` to the local airflow environment - which in my case is just a pipenv * Add a new run configuration in PyCharm * Set the python "Script path" to said airflow script * Set Parameters to test a task: `test dag_x task_y 2019-11-19...
58,931,845
My Airflow DAGs mainly consist of PythonOperators, and I would like to use my Python IDEs debug tools to develop python "inside" airflow. - I rely on Airflow's database connectors, which I think would be ugly to move "out" of airflow for development. I have been using Airflow for a bit, and have so far only achieved d...
2019/11/19
[ "https://Stackoverflow.com/questions/58931845", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5152989/" ]
Might be a little late to the party, but been looking for a solution to this as well. Wanted to be able to debug code as close to "production mode" as possible (so nothing with test etc). Found a solution in the form of the "Python Debug Server". It works the other way around: Your IDE listens and the connection is ma...
I debug `airflow test dag_id task_id`, run on a vagrant machine, using PyCharm. You should be able to use the same method, even if you're running airflow directly on localhost. [Pycharm's documentation on this subject](https://www.jetbrains.com/help/pycharm/remote-debugging-with-product.html#remote-debug-config) shoul...
58,931,845
My Airflow DAGs mainly consist of PythonOperators, and I would like to use my Python IDEs debug tools to develop python "inside" airflow. - I rely on Airflow's database connectors, which I think would be ugly to move "out" of airflow for development. I have been using Airflow for a bit, and have so far only achieved d...
2019/11/19
[ "https://Stackoverflow.com/questions/58931845", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5152989/" ]
For VSCode, the following debug configuration attaches the builtin debugger ``` { "name": "Airflow Test - Example", "type": "python", "request": "launch", "program": "`pyenv which airflow`", // or path to airflow "console": "integratedTerminal", "args": [ // exact ...
I debug `airflow test dag_id task_id`, run on a vagrant machine, using PyCharm. You should be able to use the same method, even if you're running airflow directly on localhost. [Pycharm's documentation on this subject](https://www.jetbrains.com/help/pycharm/remote-debugging-with-product.html#remote-debug-config) shoul...
58,931,845
My Airflow DAGs mainly consist of PythonOperators, and I would like to use my Python IDEs debug tools to develop python "inside" airflow. - I rely on Airflow's database connectors, which I think would be ugly to move "out" of airflow for development. I have been using Airflow for a bit, and have so far only achieved d...
2019/11/19
[ "https://Stackoverflow.com/questions/58931845", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5152989/" ]
Might be a little late to the party, but been looking for a solution to this as well. Wanted to be able to debug code as close to "production mode" as possible (so nothing with test etc). Found a solution in the form of the "Python Debug Server". It works the other way around: Your IDE listens and the connection is ma...
For VSCode, the following debug configuration attaches the builtin debugger ``` { "name": "Airflow Test - Example", "type": "python", "request": "launch", "program": "`pyenv which airflow`", // or path to airflow "console": "integratedTerminal", "args": [ // exact ...
55,515,401
I have a python script that dynamically create task (airflow operator) and DAG basing on a JSON file that maps every option desired. The script also dedicated function to create any operator needed. Sometimes i want to activate some conditional options based on the mapping... for example in a bigqueryOperator sometime...
2019/04/04
[ "https://Stackoverflow.com/questions/55515401", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4626682/" ]
Change `bqOperator` as below to handle that case, basically it would pass None when it won't find that field in your json: ``` def bqOperator(mappedTask): try: return BigQueryOperator( task_id=mappedTask.get('task_id'), sql=mappedTask.get('sql'), destination_dataset_table="{}.{}.{...
There is no private methods or fields in python, so you can directly set and get fields like ```py op.use_legacy_sql = True ``` Given that I strongly discourage from doing this, as this a real code smell. Instead you could modify you factory class to apply some defaults to your json data. Or even better, apply def...
63,979,298
So, I have created an html page and it gets content from Python.I am able to get the text from the python program in view.py but unable to set it as an html tags. I have setup the css and js in HTML file but only this problem is arising. Is there a way out? [![enter image description here](https://i.stack.imgur.com/951...
2020/09/20
[ "https://Stackoverflow.com/questions/63979298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13935716/" ]
It looks like all standard types (button, image, text, etc) are intercepter by ToolbarItem and converted into appropriate internal representation. But custom view (eg. shape based)... is not. So see below a demo of possible approach. Demo prepared & tested with Xcode 12 / iOS 14. [![demo](https://i.stack.imgur.com/o0...
If you drop into UIKit it's working for me. ``` struct ButtonRepresentation: UIViewRepresentable { let sfSymbolName: String let titleColor: UIColor let action: () -> () func makeUIView(context: Context) -> UIButton { let b = UIButton() let largeConfig = UIImage.SymbolConfiguration(scal...
63,979,298
So, I have created an html page and it gets content from Python.I am able to get the text from the python program in view.py but unable to set it as an html tags. I have setup the css and js in HTML file but only this problem is arising. Is there a way out? [![enter image description here](https://i.stack.imgur.com/951...
2020/09/20
[ "https://Stackoverflow.com/questions/63979298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13935716/" ]
It looks like all standard types (button, image, text, etc) are intercepter by ToolbarItem and converted into appropriate internal representation. But custom view (eg. shape based)... is not. So see below a demo of possible approach. Demo prepared & tested with Xcode 12 / iOS 14. [![demo](https://i.stack.imgur.com/o0...
The simplest solution I've found is to ditch `Button` and use `.onTapGesture` instead. ``` struct ContentView: View { var body: some View { NavigationView { Text("Hello World!") .toolbar { // To be colored RED ToolbarItem(placement: .bot...
63,979,298
So, I have created an html page and it gets content from Python.I am able to get the text from the python program in view.py but unable to set it as an html tags. I have setup the css and js in HTML file but only this problem is arising. Is there a way out? [![enter image description here](https://i.stack.imgur.com/951...
2020/09/20
[ "https://Stackoverflow.com/questions/63979298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13935716/" ]
Yep, I've been struggling with the same thing. It looks that `Buttons` are using system tint color and its style overall. Here is my take: ``` content .toolbar { ToolbarItem(placement: .navigationBarLeading) { HStack { StyledButton(image: .system("arrow.left")) { ... } ...
It looks like all standard types (button, image, text, etc) are intercepter by ToolbarItem and converted into appropriate internal representation. But custom view (eg. shape based)... is not. So see below a demo of possible approach. Demo prepared & tested with Xcode 12 / iOS 14. [![demo](https://i.stack.imgur.com/o0...
63,979,298
So, I have created an html page and it gets content from Python.I am able to get the text from the python program in view.py but unable to set it as an html tags. I have setup the css and js in HTML file but only this problem is arising. Is there a way out? [![enter image description here](https://i.stack.imgur.com/951...
2020/09/20
[ "https://Stackoverflow.com/questions/63979298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13935716/" ]
It looks like all standard types (button, image, text, etc) are intercepter by ToolbarItem and converted into appropriate internal representation. But custom view (eg. shape based)... is not. So see below a demo of possible approach. Demo prepared & tested with Xcode 12 / iOS 14. [![demo](https://i.stack.imgur.com/o0...
Sadly this trick only works on iOS. But on the bright side it also works for Menu as well: ``` Menu { Button("A title") {} } label : { HStack { Label("Star"), systemImage: "star") .labelStyle(.iconOnly) .foregroundColor(.red) Spacer(minLength: 0) ...
63,979,298
So, I have created an html page and it gets content from Python.I am able to get the text from the python program in view.py but unable to set it as an html tags. I have setup the css and js in HTML file but only this problem is arising. Is there a way out? [![enter image description here](https://i.stack.imgur.com/951...
2020/09/20
[ "https://Stackoverflow.com/questions/63979298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13935716/" ]
Yep, I've been struggling with the same thing. It looks that `Buttons` are using system tint color and its style overall. Here is my take: ``` content .toolbar { ToolbarItem(placement: .navigationBarLeading) { HStack { StyledButton(image: .system("arrow.left")) { ... } ...
If you drop into UIKit it's working for me. ``` struct ButtonRepresentation: UIViewRepresentable { let sfSymbolName: String let titleColor: UIColor let action: () -> () func makeUIView(context: Context) -> UIButton { let b = UIButton() let largeConfig = UIImage.SymbolConfiguration(scal...
63,979,298
So, I have created an html page and it gets content from Python.I am able to get the text from the python program in view.py but unable to set it as an html tags. I have setup the css and js in HTML file but only this problem is arising. Is there a way out? [![enter image description here](https://i.stack.imgur.com/951...
2020/09/20
[ "https://Stackoverflow.com/questions/63979298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13935716/" ]
If you drop into UIKit it's working for me. ``` struct ButtonRepresentation: UIViewRepresentable { let sfSymbolName: String let titleColor: UIColor let action: () -> () func makeUIView(context: Context) -> UIButton { let b = UIButton() let largeConfig = UIImage.SymbolConfiguration(scal...
Sadly this trick only works on iOS. But on the bright side it also works for Menu as well: ``` Menu { Button("A title") {} } label : { HStack { Label("Star"), systemImage: "star") .labelStyle(.iconOnly) .foregroundColor(.red) Spacer(minLength: 0) ...
63,979,298
So, I have created an html page and it gets content from Python.I am able to get the text from the python program in view.py but unable to set it as an html tags. I have setup the css and js in HTML file but only this problem is arising. Is there a way out? [![enter image description here](https://i.stack.imgur.com/951...
2020/09/20
[ "https://Stackoverflow.com/questions/63979298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13935716/" ]
Yep, I've been struggling with the same thing. It looks that `Buttons` are using system tint color and its style overall. Here is my take: ``` content .toolbar { ToolbarItem(placement: .navigationBarLeading) { HStack { StyledButton(image: .system("arrow.left")) { ... } ...
The simplest solution I've found is to ditch `Button` and use `.onTapGesture` instead. ``` struct ContentView: View { var body: some View { NavigationView { Text("Hello World!") .toolbar { // To be colored RED ToolbarItem(placement: .bot...
63,979,298
So, I have created an html page and it gets content from Python.I am able to get the text from the python program in view.py but unable to set it as an html tags. I have setup the css and js in HTML file but only this problem is arising. Is there a way out? [![enter image description here](https://i.stack.imgur.com/951...
2020/09/20
[ "https://Stackoverflow.com/questions/63979298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13935716/" ]
The simplest solution I've found is to ditch `Button` and use `.onTapGesture` instead. ``` struct ContentView: View { var body: some View { NavigationView { Text("Hello World!") .toolbar { // To be colored RED ToolbarItem(placement: .bot...
Sadly this trick only works on iOS. But on the bright side it also works for Menu as well: ``` Menu { Button("A title") {} } label : { HStack { Label("Star"), systemImage: "star") .labelStyle(.iconOnly) .foregroundColor(.red) Spacer(minLength: 0) ...
63,979,298
So, I have created an html page and it gets content from Python.I am able to get the text from the python program in view.py but unable to set it as an html tags. I have setup the css and js in HTML file but only this problem is arising. Is there a way out? [![enter image description here](https://i.stack.imgur.com/951...
2020/09/20
[ "https://Stackoverflow.com/questions/63979298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13935716/" ]
Yep, I've been struggling with the same thing. It looks that `Buttons` are using system tint color and its style overall. Here is my take: ``` content .toolbar { ToolbarItem(placement: .navigationBarLeading) { HStack { StyledButton(image: .system("arrow.left")) { ... } ...
Sadly this trick only works on iOS. But on the bright side it also works for Menu as well: ``` Menu { Button("A title") {} } label : { HStack { Label("Star"), systemImage: "star") .labelStyle(.iconOnly) .foregroundColor(.red) Spacer(minLength: 0) ...
7,451,347
I'm programming an iOS application which needs to communicate with a python app in a very effecient way thru UDP sockets. In the middle I have a bonjour service which serves as a bridge for my iOS app and host python app to communicate. I'm building my own protocol which is a simple C structure. The code that I had...
2011/09/16
[ "https://Stackoverflow.com/questions/7451347", "https://Stackoverflow.com", "https://Stackoverflow.com/users/933104/" ]
Yes, it is possible. Read the [Archives and Serializations Programming Guide](http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Archiving/Archiving.html), everything is explained here with samples, including this case, especially the part [Encoding and decoding C Data Types](http://developer.apple...
Rather than use NSData - and if the struct contains simple data items, rather than objects pointers you can use NSValue ``` NSValue valueFromStruct = [[NSValue value:&aStruct withObjCType:@encode(YourStructType)] retain]; ``` As NSValue conforms to the NSCoding protocol you can use the methods that you want to use.
68,382,302
I am using a MacOS 10.15 and Python version 3.7.7 I wanted to upgrade pip so I ran `pip install --upgrade pip`, but it turns out my pip was gone (it shows `ImportError: No module named pip` when I want to use `pip install ...`) I tried several methods like `python3 -m ensurepip`, but it returns ``` Looking in links:...
2021/07/14
[ "https://Stackoverflow.com/questions/68382302", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14438351/" ]
Try the following: ```sh python3 -m pip --upgrade pip ``` The `-m` flag will run a library module as a script.
The pip used by python3 is called pip3. Since you're using python3, you want to do `pip3 install --upgrade pip`.
68,382,302
I am using a MacOS 10.15 and Python version 3.7.7 I wanted to upgrade pip so I ran `pip install --upgrade pip`, but it turns out my pip was gone (it shows `ImportError: No module named pip` when I want to use `pip install ...`) I tried several methods like `python3 -m ensurepip`, but it returns ``` Looking in links:...
2021/07/14
[ "https://Stackoverflow.com/questions/68382302", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14438351/" ]
Try the following: ```sh python3 -m pip --upgrade pip ``` The `-m` flag will run a library module as a script.
Since it says no module named pip, thus pip is not installed in your system So you may try ``` curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py ``` to download pip directly then you can use execute it using - ``` python3 get-pip.py ``` For details you may refer - <https://www.geeksforgeeks.org/how-to-insta...
62,451,944
``` class TempClass(): def __init__(self,*args): for i in range(len(args)): self.number1=args[0] self.number2=args[1] print(self.number1,self.number2) temp1=TempClass(10,20) ``` output: 10 20 ``` class TempClass2(): def __init__(self,*args): for i in range(len(args)): self.number...
2020/06/18
[ "https://Stackoverflow.com/questions/62451944", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5985980/" ]
You first need to initialize `self.number1` with `[None] * 2` (or similar) before using it. However, I would use `args` directly: ``` class TempClass3(): def __init__(self,*args): self.number1 = list(args) print(self.number1) temp3=TempClass3(10,20) ```
When you are calling self.number1[0]=args[0], you are asking python to first open the list self.number1 which doesn't exist, then find an element in this non-existent list. If it doesn't exist but you pass it a value, like self.number1=args[0], python will create self.number1 and define self.number1 as args[0]. You c...
62,451,944
``` class TempClass(): def __init__(self,*args): for i in range(len(args)): self.number1=args[0] self.number2=args[1] print(self.number1,self.number2) temp1=TempClass(10,20) ``` output: 10 20 ``` class TempClass2(): def __init__(self,*args): for i in range(len(args)): self.number...
2020/06/18
[ "https://Stackoverflow.com/questions/62451944", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5985980/" ]
You first need to initialize `self.number1` with `[None] * 2` (or similar) before using it. However, I would use `args` directly: ``` class TempClass3(): def __init__(self,*args): self.number1 = list(args) print(self.number1) temp3=TempClass3(10,20) ```
In this code: ``` class TempClass3(): def __init__(self,*args): for i in range(len(args)): self.number1[0]=args[0] self.number1[1]=args[1] print(self.number1) ``` you're attempting to access a list called `self.number1` that doesn't exist yet. Instead you want to do someth...
53,107,475
I am trying to install kdb on the jupyter-notebook. First I download the 64-bit windows version on <https://ondemand.kx.com/> and also download the licence in the email. Then I open it using window command prompt. I set QHOME and PATH using the following code in command prompt: ``` setx QHOME "C:\q" setx PATH "%PATH...
2018/11/01
[ "https://Stackoverflow.com/questions/53107475", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10105915/" ]
You didn't give us the requirements for the individual filenames, but here is an example that uses a sequential number for each given filename. ``` count = 0 for item in all_news: count += 1 filename = '{}.txt'.format(count) with open(filename, 'w') as f_out: f.write('{}\n'.format(item)) ```
You have to open a new file on each element of the list, and you will need a counter to ensure have separated filenames (or a second list). ``` counter=0 for item in all_news: with open('your_file_'+str(counter)+'.txt', 'w') as f: f.write("%s\n" % item) counter = counter + 1 ``` This will write e...
53,107,475
I am trying to install kdb on the jupyter-notebook. First I download the 64-bit windows version on <https://ondemand.kx.com/> and also download the licence in the email. Then I open it using window command prompt. I set QHOME and PATH using the following code in command prompt: ``` setx QHOME "C:\q" setx PATH "%PATH...
2018/11/01
[ "https://Stackoverflow.com/questions/53107475", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10105915/" ]
Something like this? ``` all_news = ['a', 'b', 'c'] for item in all_news: # every file will get the item name # if there aren't repeated items with open(f'{item}.txt', 'w') as f: f.write("%s\n" % item) ``` If in the list are more items with the same name: ``` for count, item in enumerate(all_ne...
You have to open a new file on each element of the list, and you will need a counter to ensure have separated filenames (or a second list). ``` counter=0 for item in all_news: with open('your_file_'+str(counter)+'.txt', 'w') as f: f.write("%s\n" % item) counter = counter + 1 ``` This will write e...
33,340,749
I have registered on Google Developers Console, but my project is not a billed project. I did the steps of “initialized environment.” and “Build and Run ”as the web pages <https://github.com/GoogleCloudPlatform/datalab/wiki/Development-Environment> and <https://github.com/GoogleCloudPlatform/datalab/wiki/Build-and-Run>...
2015/10/26
[ "https://Stackoverflow.com/questions/33340749", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5488148/" ]
If you are looking to run Datalab container locally instead of running it in Google Cloud, that is also possible as described here: <https://github.com/GoogleCloudPlatform/datalab/wiki/Build-and-Run> However, that is developer setup for building/changing Datalab code and not currently geared towards a data scientist /...
If your project does not have billing enabled you cannot run queries against BigQuery, which is what it looks like you are trying to do.
33,340,749
I have registered on Google Developers Console, but my project is not a billed project. I did the steps of “initialized environment.” and “Build and Run ”as the web pages <https://github.com/GoogleCloudPlatform/datalab/wiki/Development-Environment> and <https://github.com/GoogleCloudPlatform/datalab/wiki/Build-and-Run>...
2015/10/26
[ "https://Stackoverflow.com/questions/33340749", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5488148/" ]
If you are looking to run Datalab container locally instead of running it in Google Cloud, that is also possible as described here: <https://github.com/GoogleCloudPlatform/datalab/wiki/Build-and-Run> However, that is developer setup for building/changing Datalab code and not currently geared towards a data scientist /...
Follow the steps in the quickstart guide titled [Run Cloud Datalab locally](https://cloud.google.com/datalab/docs/quickstarts/quickstart-local) to run datalab locally without setting up a datalab dev environment.
32,260,538
So i have this script in python. It uses models from django to get some (to be precise: a lot of) data from database. A quick 'summary' of what i want to achieve (it might be not so important, so you can as well get it just by looking at the code): There are objects of A type. For each A object there are related...
2015/08/27
[ "https://Stackoverflow.com/questions/32260538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3915216/" ]
Alright so my main problem was that I couldn't get the \_id of the document I inserted without not being able to check whether if it was updated/found or inserted. However I learned that you can generate your own Id's. ``` id = mongoose.Types.ObjectId(); Chatrooms.findOneAndUpdate({Roomname: room.Roomname},{ $set...
I'm afraid Using **FindOneAndUpdate** can't do what you whant because it doesn't has middleware and setter and it mention it the docs: Although values are cast to their appropriate types when using the findAndModify helpers, the following are not applied: * defaults * Setters * validators * middleware <http://mongoo...
32,260,538
So i have this script in python. It uses models from django to get some (to be precise: a lot of) data from database. A quick 'summary' of what i want to achieve (it might be not so important, so you can as well get it just by looking at the code): There are objects of A type. For each A object there are related...
2015/08/27
[ "https://Stackoverflow.com/questions/32260538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3915216/" ]
Version 4.1.10 of Mongoose has an option called `passRawResult` which if set to `true` causes the `raw` parameter to be passed. Leaving out this option seems to default to `false` and cause `raw` to always be `undefined`: > > passRawResult: if true, passes the raw result from the MongoDB driver > as the third callba...
I'm afraid Using **FindOneAndUpdate** can't do what you whant because it doesn't has middleware and setter and it mention it the docs: Although values are cast to their appropriate types when using the findAndModify helpers, the following are not applied: * defaults * Setters * validators * middleware <http://mongoo...
32,260,538
So i have this script in python. It uses models from django to get some (to be precise: a lot of) data from database. A quick 'summary' of what i want to achieve (it might be not so important, so you can as well get it just by looking at the code): There are objects of A type. For each A object there are related...
2015/08/27
[ "https://Stackoverflow.com/questions/32260538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3915216/" ]
As of 8 August 2019 (Mongoose Version 5.6.9), the property to set is "rawResult" and not "passRawResult": ``` M.findOneAndUpdate({}, obj, {new: true, upsert: true, rawResult:true}, function(err, d) { if(err) console.log(err); console.log(d); }); ``` Output: ``` { lastErrorObject: { n: 1, updatedExis...
I'm afraid Using **FindOneAndUpdate** can't do what you whant because it doesn't has middleware and setter and it mention it the docs: Although values are cast to their appropriate types when using the findAndModify helpers, the following are not applied: * defaults * Setters * validators * middleware <http://mongoo...
32,260,538
So i have this script in python. It uses models from django to get some (to be precise: a lot of) data from database. A quick 'summary' of what i want to achieve (it might be not so important, so you can as well get it just by looking at the code): There are objects of A type. For each A object there are related...
2015/08/27
[ "https://Stackoverflow.com/questions/32260538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3915216/" ]
Alright so my main problem was that I couldn't get the \_id of the document I inserted without not being able to check whether if it was updated/found or inserted. However I learned that you can generate your own Id's. ``` id = mongoose.Types.ObjectId(); Chatrooms.findOneAndUpdate({Roomname: room.Roomname},{ $set...
I don't know how this got completely off track, but there as always been a "third" argument response to all `.XXupdate()` methods, which is basically the raw response from the driver. This always tells you whether the document is "upserted" or not: ```js Chatrooms.findOneAndUpdate( { "Roomname": room.Roomname }, ...
32,260,538
So i have this script in python. It uses models from django to get some (to be precise: a lot of) data from database. A quick 'summary' of what i want to achieve (it might be not so important, so you can as well get it just by looking at the code): There are objects of A type. For each A object there are related...
2015/08/27
[ "https://Stackoverflow.com/questions/32260538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3915216/" ]
Version 4.1.10 of Mongoose has an option called `passRawResult` which if set to `true` causes the `raw` parameter to be passed. Leaving out this option seems to default to `false` and cause `raw` to always be `undefined`: > > passRawResult: if true, passes the raw result from the MongoDB driver > as the third callba...
I don't know how this got completely off track, but there as always been a "third" argument response to all `.XXupdate()` methods, which is basically the raw response from the driver. This always tells you whether the document is "upserted" or not: ```js Chatrooms.findOneAndUpdate( { "Roomname": room.Roomname }, ...
32,260,538
So i have this script in python. It uses models from django to get some (to be precise: a lot of) data from database. A quick 'summary' of what i want to achieve (it might be not so important, so you can as well get it just by looking at the code): There are objects of A type. For each A object there are related...
2015/08/27
[ "https://Stackoverflow.com/questions/32260538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3915216/" ]
As of 8 August 2019 (Mongoose Version 5.6.9), the property to set is "rawResult" and not "passRawResult": ``` M.findOneAndUpdate({}, obj, {new: true, upsert: true, rawResult:true}, function(err, d) { if(err) console.log(err); console.log(d); }); ``` Output: ``` { lastErrorObject: { n: 1, updatedExis...
I don't know how this got completely off track, but there as always been a "third" argument response to all `.XXupdate()` methods, which is basically the raw response from the driver. This always tells you whether the document is "upserted" or not: ```js Chatrooms.findOneAndUpdate( { "Roomname": room.Roomname }, ...
32,260,538
So i have this script in python. It uses models from django to get some (to be precise: a lot of) data from database. A quick 'summary' of what i want to achieve (it might be not so important, so you can as well get it just by looking at the code): There are objects of A type. For each A object there are related...
2015/08/27
[ "https://Stackoverflow.com/questions/32260538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3915216/" ]
Alright so my main problem was that I couldn't get the \_id of the document I inserted without not being able to check whether if it was updated/found or inserted. However I learned that you can generate your own Id's. ``` id = mongoose.Types.ObjectId(); Chatrooms.findOneAndUpdate({Roomname: room.Roomname},{ $set...
Version 4.1.10 of Mongoose has an option called `passRawResult` which if set to `true` causes the `raw` parameter to be passed. Leaving out this option seems to default to `false` and cause `raw` to always be `undefined`: > > passRawResult: if true, passes the raw result from the MongoDB driver > as the third callba...
32,260,538
So i have this script in python. It uses models from django to get some (to be precise: a lot of) data from database. A quick 'summary' of what i want to achieve (it might be not so important, so you can as well get it just by looking at the code): There are objects of A type. For each A object there are related...
2015/08/27
[ "https://Stackoverflow.com/questions/32260538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3915216/" ]
As of 8 August 2019 (Mongoose Version 5.6.9), the property to set is "rawResult" and not "passRawResult": ``` M.findOneAndUpdate({}, obj, {new: true, upsert: true, rawResult:true}, function(err, d) { if(err) console.log(err); console.log(d); }); ``` Output: ``` { lastErrorObject: { n: 1, updatedExis...
Version 4.1.10 of Mongoose has an option called `passRawResult` which if set to `true` causes the `raw` parameter to be passed. Leaving out this option seems to default to `false` and cause `raw` to always be `undefined`: > > passRawResult: if true, passes the raw result from the MongoDB driver > as the third callba...
26,975,539
I thought that the standalone PsychoPy install could coexist happily if Python was installed separately on the PC to but I can't get it to, nor can I find any docs. (I'm using Windows 7) I have the lastest standalone version installed and the shortcut to run it is ``` "D:\Program Files (x86)\PsychoPy2\pythonw.exe" "D...
2014/11/17
[ "https://Stackoverflow.com/questions/26975539", "https://Stackoverflow.com", "https://Stackoverflow.com/users/765827/" ]
It is not a button documented by Qt. You can detect this by catching events and checking event type: <http://qt-project.org/doc/qt-5/qevent.html#Type-enum> There are different types as `QEvent::EnterWhatsThisMode` `QEvent::WhatsThisClicked` and so on. I achieved something similar to what are you looking for using eve...
Based on Chernobyl's answer, this is how I did it in Python (PySide): ``` def event(self, event): if event.type() == QtCore.QEvent.EnterWhatsThisMode: print "click" return True return QtGui.QDialog.event(self, event) ``` That is, you reimplement `event` when app enters 'WhatsThisMode'. Other...
26,975,539
I thought that the standalone PsychoPy install could coexist happily if Python was installed separately on the PC to but I can't get it to, nor can I find any docs. (I'm using Windows 7) I have the lastest standalone version installed and the shortcut to run it is ``` "D:\Program Files (x86)\PsychoPy2\pythonw.exe" "D...
2014/11/17
[ "https://Stackoverflow.com/questions/26975539", "https://Stackoverflow.com", "https://Stackoverflow.com/users/765827/" ]
The other answers were a bit misleading for me, focusing only on catching the question mark event, but not explaining the normal usage. When this button is clicked and *WhatsThisMode* is triggered, the elements of the dialog are supposed to give info about themselves. And if mouse hovers over an element that supports...
It is not a button documented by Qt. You can detect this by catching events and checking event type: <http://qt-project.org/doc/qt-5/qevent.html#Type-enum> There are different types as `QEvent::EnterWhatsThisMode` `QEvent::WhatsThisClicked` and so on. I achieved something similar to what are you looking for using eve...
26,975,539
I thought that the standalone PsychoPy install could coexist happily if Python was installed separately on the PC to but I can't get it to, nor can I find any docs. (I'm using Windows 7) I have the lastest standalone version installed and the shortcut to run it is ``` "D:\Program Files (x86)\PsychoPy2\pythonw.exe" "D...
2014/11/17
[ "https://Stackoverflow.com/questions/26975539", "https://Stackoverflow.com", "https://Stackoverflow.com/users/765827/" ]
The other answers were a bit misleading for me, focusing only on catching the question mark event, but not explaining the normal usage. When this button is clicked and *WhatsThisMode* is triggered, the elements of the dialog are supposed to give info about themselves. And if mouse hovers over an element that supports...
Based on Chernobyl's answer, this is how I did it in Python (PySide): ``` def event(self, event): if event.type() == QtCore.QEvent.EnterWhatsThisMode: print "click" return True return QtGui.QDialog.event(self, event) ``` That is, you reimplement `event` when app enters 'WhatsThisMode'. Other...
59,598,620
I am creating my first Django project. I have successfully installed Django version 2.1. When I created the project, the project was successfully launched at the url 127.0.0.1:8000. Then I ran the command **python manage.py startapp products**. Products folder was also successfully created in the project. Then inside t...
2020/01/05
[ "https://Stackoverflow.com/questions/59598620", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12655703/" ]
In you **settings.py** add the app to the **INSTALLED\_APPS** list as: ```py INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'products' # <-- your product a...
Check if you had ran the command below: `python manage.py runserver` If you had run the above command and the error persists, try to run on the global address 0.0.0.0 ``` python manage.py runserver 0.0.0.0:8000 ``` OR on a different port ``` python manage.py runserver 0.0.0.0:8001 ```
46,368,459
I have different types of `ISO 8601` formatted date strings, using `datetime library`, i want to obtain a `datetime object` from these strings. Example of the input strings: 1. `2017-08-01` (1st august 2017) 2. `2017-09` (september of 2017) 3. `2017-W20` (20th week) 4. `2017-W37-2` (tuesday of 37th week) I am able t...
2017/09/22
[ "https://Stackoverflow.com/questions/46368459", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6374328/" ]
You can escape the Twig tags (as described [here](https://twig.symfony.com/doc/2.x/templates.html#escaping)) using `{{ '{{' }}`, `{{ '}}' }}`, `{{ '{%' }}` and `{{ '%}' }}`. ``` $input = '<h1>{{ pageTitle }}</h1> <div class="row"> {% for product in products %} <span class="mep"></span> {% endfor %} </div>...
My regex solution (better solution still welcome): ``` $input = '<h1>{{ pageTitle }}</h1> <div class="row"> {% for product in products %} <span class="mep"></span> {% endfor %} </div>'; $search = '/({{.+}})|({%.+%})/si'; $replace = ''; echo preg_replace($input, $search, $replace); ```
31,768,128
I don't know what's the deal but I am stuck following some stackoverflow solutions which gets nowhere. Can you please help me on this? ``` Monas-MacBook-Pro:CS764 mona$ sudo python get-pip.py The directory '/Users/mona/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cach...
2015/08/02
[ "https://Stackoverflow.com/questions/31768128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2414957/" ]
I'm guessing you have two python installs, or two pip installs, one of which has been partially removed. Why do you use `sudo`? Ideally you should be able to install and run everything from your user account instead of using root. If you mix root and your local account together you are more likely to run into permissi...
For me, on centOS 7 I had to remove the old pip link from /bin by ```sh rm /bin/pip2.7 rm /bin/pip ``` then relink it with ```sh sudo ln -s /usr/local/bin/pip2.7 /bin/pip2.7 ``` Then if ```sh /usr/local/bin/pip2.7 ``` Works, this should work
31,768,128
I don't know what's the deal but I am stuck following some stackoverflow solutions which gets nowhere. Can you please help me on this? ``` Monas-MacBook-Pro:CS764 mona$ sudo python get-pip.py The directory '/Users/mona/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cach...
2015/08/02
[ "https://Stackoverflow.com/questions/31768128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2414957/" ]
I made the same error using sudo for my installation. (oops) ``` brew install python brew linkapps python brew link --overwrite python ``` This brought everything back to normal.
This error typically pops up every time there is an iOS upgrade. Try ``` xcode-select --install ``` This will install the latest xcode version and that should fix it
31,768,128
I don't know what's the deal but I am stuck following some stackoverflow solutions which gets nowhere. Can you please help me on this? ``` Monas-MacBook-Pro:CS764 mona$ sudo python get-pip.py The directory '/Users/mona/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cach...
2015/08/02
[ "https://Stackoverflow.com/questions/31768128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2414957/" ]
In case it helps anyone, the solution mentioned in this other question worked for me when pip stopped working today after upgrading it: [Pip broken after upgrading](https://stackoverflow.com/questions/26302805/pip-broken-after-upgrading) It seems that it's an issue when a previously cached location changes, so you can...
I got same problem. If I run `brew link --overwrite python2`. There was still `zsh: /usr/local/bin//fab: bad interpreter: /usr/local/opt/python/bin/python2.7: no such file or directory`. ``` cd /usr/local/opt/ mv python2 python ``` Solved it! Now we can use python2 version fabric. === 2018/07/25 updated There is c...
31,768,128
I don't know what's the deal but I am stuck following some stackoverflow solutions which gets nowhere. Can you please help me on this? ``` Monas-MacBook-Pro:CS764 mona$ sudo python get-pip.py The directory '/Users/mona/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cach...
2015/08/02
[ "https://Stackoverflow.com/questions/31768128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2414957/" ]
Editing the first line of this file worked to me: `MBP-de-Jose:~ josejunior$ which python3` ``` /usr/local/Cellar/python/3.7.3/bin/python3 ``` `MBP-de-Jose:~ josejunior$` before ``` #!/usr/local/opt/python/bin/python3.7 ``` after ``` #!/usr/local/Cellar/python/3.7.3/bin/python3 ```
This error typically pops up every time there is an iOS upgrade. Try ``` xcode-select --install ``` This will install the latest xcode version and that should fix it
31,768,128
I don't know what's the deal but I am stuck following some stackoverflow solutions which gets nowhere. Can you please help me on this? ``` Monas-MacBook-Pro:CS764 mona$ sudo python get-pip.py The directory '/Users/mona/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cach...
2015/08/02
[ "https://Stackoverflow.com/questions/31768128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2414957/" ]
In case it helps anyone, the solution mentioned in this other question worked for me when pip stopped working today after upgrading it: [Pip broken after upgrading](https://stackoverflow.com/questions/26302805/pip-broken-after-upgrading) It seems that it's an issue when a previously cached location changes, so you can...
This error typically pops up every time there is an iOS upgrade. Try ``` xcode-select --install ``` This will install the latest xcode version and that should fix it
31,768,128
I don't know what's the deal but I am stuck following some stackoverflow solutions which gets nowhere. Can you please help me on this? ``` Monas-MacBook-Pro:CS764 mona$ sudo python get-pip.py The directory '/Users/mona/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cach...
2015/08/02
[ "https://Stackoverflow.com/questions/31768128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2414957/" ]
To simplify to operation, we can use the below command to reinstall version 2: `brew install python@2` Then on my mac, it looks as below: ``` ▶ python -V Python 2.7.10 ▶ python2 -V Python 2.7.14 ▶ python3 -V Python 3.6.5 ▶ pip2 -V pip 9.0.3 from /usr/local/lib/python2.7/site-packages (python 2.7) ▶ pip3 -V pip 9...
I had the same issue. I have both Python 2.7 & 3.6 installed. Python 2.7 had `virtualenv` working, but after installing Python3, virtualenv kept looking for version 2.7 and couldn't find it. Doing `pip install virtualenv` installed the Python3 version of virtualenv. Then, for each command, if I want to use Python2, I...
31,768,128
I don't know what's the deal but I am stuck following some stackoverflow solutions which gets nowhere. Can you please help me on this? ``` Monas-MacBook-Pro:CS764 mona$ sudo python get-pip.py The directory '/Users/mona/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cach...
2015/08/02
[ "https://Stackoverflow.com/questions/31768128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2414957/" ]
Only solution in OSX and its variant. ``` ln -s /usr/local/bin/python /usr/local/opt/python/bin/python2.7 ```
``` sudo /usr/bin/easy_install pip ``` this command worked out for me
31,768,128
I don't know what's the deal but I am stuck following some stackoverflow solutions which gets nowhere. Can you please help me on this? ``` Monas-MacBook-Pro:CS764 mona$ sudo python get-pip.py The directory '/Users/mona/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cach...
2015/08/02
[ "https://Stackoverflow.com/questions/31768128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2414957/" ]
I had the same issue, virtualenv was pointing to an old python path. Fixing the path resolved the issue: ``` $ virtualenv -p python2.7 env -bash: /usr/local/bin/virtualenv: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory $ which python2.7 /opt/local/bin/python2.7 # needed to change to...
You could have two different versions of Python and pip. Try to: `pip2 install --upgrade pip` and then `pip2 install -r requirements.txt` Or `pip3` if you are on newer Python version.
31,768,128
I don't know what's the deal but I am stuck following some stackoverflow solutions which gets nowhere. Can you please help me on this? ``` Monas-MacBook-Pro:CS764 mona$ sudo python get-pip.py The directory '/Users/mona/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cach...
2015/08/02
[ "https://Stackoverflow.com/questions/31768128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2414957/" ]
I'm guessing you have two python installs, or two pip installs, one of which has been partially removed. Why do you use `sudo`? Ideally you should be able to install and run everything from your user account instead of using root. If you mix root and your local account together you are more likely to run into permissi...
In my case, I decided to remove the homebrew python installation from my mac as I already had two other versions of python installed on my mac through MacPorts. This caused the error message. Reinstalling python through brew solved my issue.
31,768,128
I don't know what's the deal but I am stuck following some stackoverflow solutions which gets nowhere. Can you please help me on this? ``` Monas-MacBook-Pro:CS764 mona$ sudo python get-pip.py The directory '/Users/mona/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cach...
2015/08/02
[ "https://Stackoverflow.com/questions/31768128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2414957/" ]
Because I had both python 2 and 3 installed on Mac OSX I was having all sorts of errors. I used which to find the location of my python2.7 file (/usr/local/bin/python2.7) ``` which python2.7 ``` Then I symlinked my real python2.7 install location with the one the script expected: ``` ln -s /usr/local/bin/python2.7...
You could have two different versions of Python and pip. Try to: `pip2 install --upgrade pip` and then `pip2 install -r requirements.txt` Or `pip3` if you are on newer Python version.
10,529,461
I just noticed the problem with process terminate (from `multiprocessing` library) method on Linux. I have application working with `multiprocessing` library but... when I call `terminate` function on Windows everything works great, on the other hand Linux fails with this solution. As a replacement of process killing I...
2012/05/10
[ "https://Stackoverflow.com/questions/10529461", "https://Stackoverflow.com", "https://Stackoverflow.com/users/611982/" ]
From the [docs](http://docs.python.org/py3k/library/multiprocessing.html#multiprocessing.Process.terminate): > > terminate() > > > Terminate the process. On Unix this is done using the > SIGTERM signal; on Windows TerminateProcess() is used. Note that exit > handlers and finally clauses, etc., will not be execute...
Not exactly a direct answer to your question, but since you are dealing with the threads this could be helpful as well for debugging those threads: <https://stackoverflow.com/a/10165776/1019572> I recently found a bug in cherrypy using this code.
3,182,009
I'm trying to upload an image (just a random picture for now) to my MediaWiki site, but I keep getting this error: > > "Unrecognized value for parameter 'action': upload" > > > Here's what I did (site url and password changed): ``` Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) [GCC 4.2.1 (Apple Inc. build 5...
2010/07/05
[ "https://Stackoverflow.com/questions/3182009", "https://Stackoverflow.com", "https://Stackoverflow.com/users/383971/" ]
You need at least MediaWiki 1.16 (which is currently in begta) to be able to upload files via the API. Or you can try [mwclient](http://mwclient.sf.net/), which automatically falls back to uploading via Special:Upload if an older version of MediaWiki is used (with reduced functionality, such as no error handling etc.)
Maybe you have to "obtain a token" first? > > To upload files, a token is required. This token is identical to the edit token and is the same regardless of target filename, but changes at every login. Unlike other tokens, it cannot be obtained directly, so one must obtain and use an edit token instead. > > > See...
3,182,009
I'm trying to upload an image (just a random picture for now) to my MediaWiki site, but I keep getting this error: > > "Unrecognized value for parameter 'action': upload" > > > Here's what I did (site url and password changed): ``` Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) [GCC 4.2.1 (Apple Inc. build 5...
2010/07/05
[ "https://Stackoverflow.com/questions/3182009", "https://Stackoverflow.com", "https://Stackoverflow.com/users/383971/" ]
I got so frustrated with all these troubles that I made my own simple routines using poster and the python standard cookielib and httplib2. It is located here: <https://github.com/gandrewstone/mediawiki_python_bot>
Maybe you have to "obtain a token" first? > > To upload files, a token is required. This token is identical to the edit token and is the same regardless of target filename, but changes at every login. Unlike other tokens, it cannot be obtained directly, so one must obtain and use an edit token instead. > > > See...
3,182,009
I'm trying to upload an image (just a random picture for now) to my MediaWiki site, but I keep getting this error: > > "Unrecognized value for parameter 'action': upload" > > > Here's what I did (site url and password changed): ``` Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) [GCC 4.2.1 (Apple Inc. build 5...
2010/07/05
[ "https://Stackoverflow.com/questions/3182009", "https://Stackoverflow.com", "https://Stackoverflow.com/users/383971/" ]
You need at least MediaWiki 1.16 (which is currently in begta) to be able to upload files via the API. Or you can try [mwclient](http://mwclient.sf.net/), which automatically falls back to uploading via Special:Upload if an older version of MediaWiki is used (with reduced functionality, such as no error handling etc.)
I was having similar trouble, and I was getting a raise APIError(data['error']['code'], data['error']['info']) wikitools.api.APIError: (u'verification-error', u'This file did not pass file verification') However, I found that the target page needs to be the same type as the file, and you should open the file for bin...
3,182,009
I'm trying to upload an image (just a random picture for now) to my MediaWiki site, but I keep getting this error: > > "Unrecognized value for parameter 'action': upload" > > > Here's what I did (site url and password changed): ``` Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) [GCC 4.2.1 (Apple Inc. build 5...
2010/07/05
[ "https://Stackoverflow.com/questions/3182009", "https://Stackoverflow.com", "https://Stackoverflow.com/users/383971/" ]
You need at least MediaWiki 1.16 (which is currently in begta) to be able to upload files via the API. Or you can try [mwclient](http://mwclient.sf.net/), which automatically falls back to uploading via Special:Upload if an older version of MediaWiki is used (with reduced functionality, such as no error handling etc.)
I got so frustrated with all these troubles that I made my own simple routines using poster and the python standard cookielib and httplib2. It is located here: <https://github.com/gandrewstone/mediawiki_python_bot>
3,182,009
I'm trying to upload an image (just a random picture for now) to my MediaWiki site, but I keep getting this error: > > "Unrecognized value for parameter 'action': upload" > > > Here's what I did (site url and password changed): ``` Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) [GCC 4.2.1 (Apple Inc. build 5...
2010/07/05
[ "https://Stackoverflow.com/questions/3182009", "https://Stackoverflow.com", "https://Stackoverflow.com/users/383971/" ]
I got so frustrated with all these troubles that I made my own simple routines using poster and the python standard cookielib and httplib2. It is located here: <https://github.com/gandrewstone/mediawiki_python_bot>
I was having similar trouble, and I was getting a raise APIError(data['error']['code'], data['error']['info']) wikitools.api.APIError: (u'verification-error', u'This file did not pass file verification') However, I found that the target page needs to be the same type as the file, and you should open the file for bin...
29,922,373
I'm doing a fair amount of parallel processing in Python using the multiprocessing module. I know certain objects CAN be pickle (thus passed as arguments in multi-p) and others can't. E.g. ``` class abc(): pass a=abc() pickle.dumps(a) 'ccopy_reg\n_reconstructor\np1\n(c__main__\nabc\np2\nc__builtin__\nobject\np3\n...
2015/04/28
[ "https://Stackoverflow.com/questions/29922373", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1415450/" ]
From the [docs](https://docs.python.org/2/library/pickle.html#what-can-be-pickled-and-unpickled): > > The following types can be pickled: > > > * `None`, `True`, and `False` > * integers, long integers, floating point numbers, complex numbers > * normal and Unicode strings > * tuples, lists, sets, and dictionaries ...
The general rule of thumb is that "logical" objects can be pickled, but "resource" objects (files, locks) can't, because it makes no sense to persist/clone them.
29,922,373
I'm doing a fair amount of parallel processing in Python using the multiprocessing module. I know certain objects CAN be pickle (thus passed as arguments in multi-p) and others can't. E.g. ``` class abc(): pass a=abc() pickle.dumps(a) 'ccopy_reg\n_reconstructor\np1\n(c__main__\nabc\np2\nc__builtin__\nobject\np3\n...
2015/04/28
[ "https://Stackoverflow.com/questions/29922373", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1415450/" ]
From the [docs](https://docs.python.org/2/library/pickle.html#what-can-be-pickled-and-unpickled): > > The following types can be pickled: > > > * `None`, `True`, and `False` > * integers, long integers, floating point numbers, complex numbers > * normal and Unicode strings > * tuples, lists, sets, and dictionaries ...
In addition to icedtrees' answer, also coming straight from the [docs](https://docs.python.org/3.5/library/pickle.html#pickle-inst), you can customize and control how class instances are pickled and unpicked, using the special methods: `object.__getnewargs_ex__()`, `object.__getnewargs__()`, `object.__getstate__()`, `o...
29,922,373
I'm doing a fair amount of parallel processing in Python using the multiprocessing module. I know certain objects CAN be pickle (thus passed as arguments in multi-p) and others can't. E.g. ``` class abc(): pass a=abc() pickle.dumps(a) 'ccopy_reg\n_reconstructor\np1\n(c__main__\nabc\np2\nc__builtin__\nobject\np3\n...
2015/04/28
[ "https://Stackoverflow.com/questions/29922373", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1415450/" ]
I'm the `dill` author. There's a fairly comprehensive list of what pickles and what doesn't as part of `dill`. It can be run per version of Python 2.5–3.4, and adjusted for what pickles with `dill` or what pickles with `pickle` by changing one flag. See [here](https://github.com/uqfoundation/dill/blob/master/tests/test...
From the [docs](https://docs.python.org/2/library/pickle.html#what-can-be-pickled-and-unpickled): > > The following types can be pickled: > > > * `None`, `True`, and `False` > * integers, long integers, floating point numbers, complex numbers > * normal and Unicode strings > * tuples, lists, sets, and dictionaries ...
29,922,373
I'm doing a fair amount of parallel processing in Python using the multiprocessing module. I know certain objects CAN be pickle (thus passed as arguments in multi-p) and others can't. E.g. ``` class abc(): pass a=abc() pickle.dumps(a) 'ccopy_reg\n_reconstructor\np1\n(c__main__\nabc\np2\nc__builtin__\nobject\np3\n...
2015/04/28
[ "https://Stackoverflow.com/questions/29922373", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1415450/" ]
I'm the `dill` author. There's a fairly comprehensive list of what pickles and what doesn't as part of `dill`. It can be run per version of Python 2.5–3.4, and adjusted for what pickles with `dill` or what pickles with `pickle` by changing one flag. See [here](https://github.com/uqfoundation/dill/blob/master/tests/test...
The general rule of thumb is that "logical" objects can be pickled, but "resource" objects (files, locks) can't, because it makes no sense to persist/clone them.
29,922,373
I'm doing a fair amount of parallel processing in Python using the multiprocessing module. I know certain objects CAN be pickle (thus passed as arguments in multi-p) and others can't. E.g. ``` class abc(): pass a=abc() pickle.dumps(a) 'ccopy_reg\n_reconstructor\np1\n(c__main__\nabc\np2\nc__builtin__\nobject\np3\n...
2015/04/28
[ "https://Stackoverflow.com/questions/29922373", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1415450/" ]
I'm the `dill` author. There's a fairly comprehensive list of what pickles and what doesn't as part of `dill`. It can be run per version of Python 2.5–3.4, and adjusted for what pickles with `dill` or what pickles with `pickle` by changing one flag. See [here](https://github.com/uqfoundation/dill/blob/master/tests/test...
In addition to icedtrees' answer, also coming straight from the [docs](https://docs.python.org/3.5/library/pickle.html#pickle-inst), you can customize and control how class instances are pickled and unpicked, using the special methods: `object.__getnewargs_ex__()`, `object.__getnewargs__()`, `object.__getstate__()`, `o...
65,346,545
I have two dense matrices with the sizes (2500, 208) and (208, 2500). I want to calculate their product. It works fine and fast when it is a single process but when it is in a multiprocessing block, the processes stuck in there for hours. I do sparse matrices multiplication with even larger sizes but I have no problem....
2020/12/17
[ "https://Stackoverflow.com/questions/65346545", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13575728/" ]
All you need to do is pass the function 'add transaction' from 'Page 2' to 'Page 3'. You have to make sure that the function 'add transaction' accepts 'Trans' as a parameter and it also calls setState for Page 2. In Page 3 you have to pass your 'Trans(true, -50)' as the parameter to the 'add transaction' function that ...
Usually there are two methods of widget interaction: callbacks (when one widget provides a callback and other one call it back) or streams (when one widget provides a stream controller and other one uses those controller to send events to stream). Callbacks and events are processed by widget-initiator. 1. Create a `Va...
45,597,031
I've looked at several other questions and none of them seem to help with my solution. I think I'm just not very intelligent sadly. Basic question I know. I decided to learn python and I'm making a basic app with tkinter to learn. Basically it's an app that stores and displays people's driving licence details (name a...
2017/08/09
[ "https://Stackoverflow.com/questions/45597031", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4140751/" ]
I'm guessing you're running into problems since you didn't specify a layout manager and passed `console` instead of `self`: ``` import tkinter as tk class Search(tk.Frame): def __init__(self, parent=None, controller=None): tk.Frame.__init__(self, parent) self.pack() # specify layout manager ...
First of all, using `from tkinter import *` is a more efficient way of importing Tkinters libraries without having to import specific things when needed. To answer your question though, here is the code for entering a text box. `t1 = Text(self)` To insert text into the text box: `t1.insert()` An example of this w...
17,964,475
Hey I'm trying to install some packages from a `requires` file on a new virtual environment (2.7.4), but I keep running into the following error: ``` CertificateError: hostname 'pypi.python.org' doesn't match either of '*.addvocate.com', 'addvocate.com' ``` I cannot seem to find anything helpful on the error whe...
2013/07/31
[ "https://Stackoverflow.com/questions/17964475", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2637052/" ]
The issue is being documented on the python status site at <http://status.python.org/incidents/jj8d7xn41hr5>
When I try to connect to pypi I get the following error: ``` pypi.python.org uses an invalid security certificate. The certificate is only valid for the following names: *.addvocate.com , addvocate.com ``` So either pypi is using the wrong ssl certificate or somehow my connection is being routed to the wrong serv...
17,964,475
Hey I'm trying to install some packages from a `requires` file on a new virtual environment (2.7.4), but I keep running into the following error: ``` CertificateError: hostname 'pypi.python.org' doesn't match either of '*.addvocate.com', 'addvocate.com' ``` I cannot seem to find anything helpful on the error whe...
2013/07/31
[ "https://Stackoverflow.com/questions/17964475", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2637052/" ]
When I try to connect to pypi I get the following error: ``` pypi.python.org uses an invalid security certificate. The certificate is only valid for the following names: *.addvocate.com , addvocate.com ``` So either pypi is using the wrong ssl certificate or somehow my connection is being routed to the wrong serv...
Changing your DNS settings should solve it for now. For my Ubuntu 12.04 Amazon AWS Instance I did the following: ``` sudo pico /etc/dhcp/dhclient.conf supersede domain-name-servers 8.8.8.8, 8.8.4.4; ``` Save the file and it was fine after a few seconds.
17,964,475
Hey I'm trying to install some packages from a `requires` file on a new virtual environment (2.7.4), but I keep running into the following error: ``` CertificateError: hostname 'pypi.python.org' doesn't match either of '*.addvocate.com', 'addvocate.com' ``` I cannot seem to find anything helpful on the error whe...
2013/07/31
[ "https://Stackoverflow.com/questions/17964475", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2637052/" ]
The issue is being documented on the python status site at <http://status.python.org/incidents/jj8d7xn41hr5>
I had the same error, I fixed it by downgrading my pip version to 1.2.1: easy\_install pip==1.2.1
17,964,475
Hey I'm trying to install some packages from a `requires` file on a new virtual environment (2.7.4), but I keep running into the following error: ``` CertificateError: hostname 'pypi.python.org' doesn't match either of '*.addvocate.com', 'addvocate.com' ``` I cannot seem to find anything helpful on the error whe...
2013/07/31
[ "https://Stackoverflow.com/questions/17964475", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2637052/" ]
I had the same error, I fixed it by downgrading my pip version to 1.2.1: easy\_install pip==1.2.1
Changing your DNS settings should solve it for now. For my Ubuntu 12.04 Amazon AWS Instance I did the following: ``` sudo pico /etc/dhcp/dhclient.conf supersede domain-name-servers 8.8.8.8, 8.8.4.4; ``` Save the file and it was fine after a few seconds.
17,964,475
Hey I'm trying to install some packages from a `requires` file on a new virtual environment (2.7.4), but I keep running into the following error: ``` CertificateError: hostname 'pypi.python.org' doesn't match either of '*.addvocate.com', 'addvocate.com' ``` I cannot seem to find anything helpful on the error whe...
2013/07/31
[ "https://Stackoverflow.com/questions/17964475", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2637052/" ]
The issue is being documented on the python status site at <http://status.python.org/incidents/jj8d7xn41hr5>
Changing your DNS settings should solve it for now. For my Ubuntu 12.04 Amazon AWS Instance I did the following: ``` sudo pico /etc/dhcp/dhclient.conf supersede domain-name-servers 8.8.8.8, 8.8.4.4; ``` Save the file and it was fine after a few seconds.
48,174,011
I'm running apache2 web server on raspberry pi3 model B. I'm setting up smart home running with Pi's and Uno's. I have a php scrypt that executes python program>index.php. It has rwxrwxrwx >I'll change that late becouse i don't fully need it. And i want to real-time display print from python script. `exec('sudo pytho...
2018/01/09
[ "https://Stackoverflow.com/questions/48174011", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8882678/" ]
shell\_exec returns the output of your script. so use ``` $cmd = escapeshellcmd('sudo python3 piUno.py'); $output = shell_exec($cmd); echo $output; ``` should work! let me know if it doesn't edit: oh hey! your question got me looking at doc to check myself and exec actually returns the last line of output if you ...
First make sure you have permissions to **write read execute for web user**. You can you user `sudo sudo chmod 777 /path/to/your/directory/file.xyz` For php file and file you want to run. `$output = exec('sudo pytho3 piUno'); echo $output;` **Credits ---> Ralph Thomas Hopper**
14,346,177
I'm trying to use factory\_boy to help generate some MongoEngine documents for my tests. I'm having trouble defining `EmbeddedDocumentField` objects. Here's my MongoEngine `Document`: ```py class Comment(EmbeddedDocument): content = StringField() name = StringField(max_length=120) class Post(Document): t...
2013/01/15
[ "https://Stackoverflow.com/questions/14346177", "https://Stackoverflow.com", "https://Stackoverflow.com/users/387163/" ]
I'm not sure if this is what you want but I just started looking at this problem and this seems to work: ``` from mongoengine import EmbeddedDocument, Document, StringField, ListField, EmbeddedDocumentField import factory class Comment(EmbeddedDocument): content = StringField() name = StringField(max_length=1...
The way that I'm doing it right now is to prevent the Factories based on EmbeddedDocuments from building. So, I've setup up an EmbeddedDocumentFactory, like so: ``` class EmbeddedDocumentFactory(factory.Factory): ABSTRACT_FACTORY = True @classmethod def _prepare(cls, create, **kwargs): ...
66,517,764
### What is the pythonic way to remove all the parts of string upto and including dot from a set ``` theSet={'products.add_product','products.add_category','books.view_books','cats.change_cats'} #desired output newSet = {'add_product','add_category','view_books', 'change_cats'} ```
2021/03/07
[ "https://Stackoverflow.com/questions/66517764", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8047262/" ]
You can use `yearmon`function from `zoo`. Then search for string Jun with R `grepl` function in Date column and apply desired condition with `case_when`from `dplyr` package. ``` library(zoo) library(dplyr) # your data Date <- c("2000-01", "2000-02", "2000-03", "2000-04", "2000-05", "2000-06", "2000-07", "2000-08", "...
Why not simply this? ``` FF5_class$HOLD <- ifelse(substr(FF5_class$Date, 6,7) =="06", FF5_class$Value, NA) Date Permno Value HOLD 1 2000-01 10026 Big, Growth <NA> 2 2000-02 10026 Small, Value <NA> 3 2000-03 10026 Neutral, Neutral <NA> 4 2000-04 ...
3,434,048
I know it can be achieved by command line but I need to pass at least 10 variables and command line will mean too much of programming since these variables may or may not be passed. Actually I have build A application half in vB( for GUI ) and Half in python( for script ). I need to pass variables to python, similar, ...
2010/08/08
[ "https://Stackoverflow.com/questions/3434048", "https://Stackoverflow.com", "https://Stackoverflow.com/users/388350/" ]
Since you're working on windows with VB, it's worth mentioning that [IronPython](http://ironpython.net/) might be one option. Since both VB and IronPython can interact through .NET, you could wrap up your script in an assembly and expose a function which you call with the required arguments.
Have you taken a look at the [getopt module](http://docs.python.org/library/getopt.html)? It's designed to make working with command line options easier. See also the examples at [Dive Into Python](http://www.faqs.org/docs/diveintopython/kgp_commandline.html). If you are working with Python 2.7 (and not lower), than y...
3,434,048
I know it can be achieved by command line but I need to pass at least 10 variables and command line will mean too much of programming since these variables may or may not be passed. Actually I have build A application half in vB( for GUI ) and Half in python( for script ). I need to pass variables to python, similar, ...
2010/08/08
[ "https://Stackoverflow.com/questions/3434048", "https://Stackoverflow.com", "https://Stackoverflow.com/users/388350/" ]
If you are using Python <2.7 I would suggest [optparse](http://docs.python.org/library/optparse.html). optparse is deprecated though, and in 2.7 you should use [argparse](http://docs.python.org/library/argparse.html#module-argparse) It makes passing named parameters a breeze.
you can do something fun like call it as ``` thepyscript.py "x = 12,y = 'hello world', z = 'jam'" ``` and inside your script, parse do: ``` stuff = arg[1].split(',') for item in stuff: exec(item) #or eval(item) depending on how complex you get #Exec can be a lot of fun :) In fact with this approach you could ...
3,434,048
I know it can be achieved by command line but I need to pass at least 10 variables and command line will mean too much of programming since these variables may or may not be passed. Actually I have build A application half in vB( for GUI ) and Half in python( for script ). I need to pass variables to python, similar, ...
2010/08/08
[ "https://Stackoverflow.com/questions/3434048", "https://Stackoverflow.com", "https://Stackoverflow.com/users/388350/" ]
you can do something fun like call it as ``` thepyscript.py "x = 12,y = 'hello world', z = 'jam'" ``` and inside your script, parse do: ``` stuff = arg[1].split(',') for item in stuff: exec(item) #or eval(item) depending on how complex you get #Exec can be a lot of fun :) In fact with this approach you could ...
What do you think about creating a python script setting these variables from the gui side? When starting the python app you just start this script and you have your vars. [Execfile](http://docs.python.org/library/functions.html#execfile)
3,434,048
I know it can be achieved by command line but I need to pass at least 10 variables and command line will mean too much of programming since these variables may or may not be passed. Actually I have build A application half in vB( for GUI ) and Half in python( for script ). I need to pass variables to python, similar, ...
2010/08/08
[ "https://Stackoverflow.com/questions/3434048", "https://Stackoverflow.com", "https://Stackoverflow.com/users/388350/" ]
Have you taken a look at the [getopt module](http://docs.python.org/library/getopt.html)? It's designed to make working with command line options easier. See also the examples at [Dive Into Python](http://www.faqs.org/docs/diveintopython/kgp_commandline.html). If you are working with Python 2.7 (and not lower), than y...
What do you think about creating a python script setting these variables from the gui side? When starting the python app you just start this script and you have your vars. [Execfile](http://docs.python.org/library/functions.html#execfile)
3,434,048
I know it can be achieved by command line but I need to pass at least 10 variables and command line will mean too much of programming since these variables may or may not be passed. Actually I have build A application half in vB( for GUI ) and Half in python( for script ). I need to pass variables to python, similar, ...
2010/08/08
[ "https://Stackoverflow.com/questions/3434048", "https://Stackoverflow.com", "https://Stackoverflow.com/users/388350/" ]
If you are using Python <2.7 I would suggest [optparse](http://docs.python.org/library/optparse.html). optparse is deprecated though, and in 2.7 you should use [argparse](http://docs.python.org/library/argparse.html#module-argparse) It makes passing named parameters a breeze.
If your script is not called too often, you can use a configuration file. [The .ini style is easily readable by ConfigParser](http://docs.python.org/library/configparser.html): ``` [Section_1] foo1=1 foo2=2 foo3=5 ... [Section_2] bar1=1 bar2=2 bar3=3 ... ``` If you have a serious amount of variables, it might be ...
3,434,048
I know it can be achieved by command line but I need to pass at least 10 variables and command line will mean too much of programming since these variables may or may not be passed. Actually I have build A application half in vB( for GUI ) and Half in python( for script ). I need to pass variables to python, similar, ...
2010/08/08
[ "https://Stackoverflow.com/questions/3434048", "https://Stackoverflow.com", "https://Stackoverflow.com/users/388350/" ]
If you are using Python <2.7 I would suggest [optparse](http://docs.python.org/library/optparse.html). optparse is deprecated though, and in 2.7 you should use [argparse](http://docs.python.org/library/argparse.html#module-argparse) It makes passing named parameters a breeze.
Have you taken a look at the [getopt module](http://docs.python.org/library/getopt.html)? It's designed to make working with command line options easier. See also the examples at [Dive Into Python](http://www.faqs.org/docs/diveintopython/kgp_commandline.html). If you are working with Python 2.7 (and not lower), than y...
3,434,048
I know it can be achieved by command line but I need to pass at least 10 variables and command line will mean too much of programming since these variables may or may not be passed. Actually I have build A application half in vB( for GUI ) and Half in python( for script ). I need to pass variables to python, similar, ...
2010/08/08
[ "https://Stackoverflow.com/questions/3434048", "https://Stackoverflow.com", "https://Stackoverflow.com/users/388350/" ]
Since you're working on windows with VB, it's worth mentioning that [IronPython](http://ironpython.net/) might be one option. Since both VB and IronPython can interact through .NET, you could wrap up your script in an assembly and expose a function which you call with the required arguments.
If your script is not called too often, you can use a configuration file. [The .ini style is easily readable by ConfigParser](http://docs.python.org/library/configparser.html): ``` [Section_1] foo1=1 foo2=2 foo3=5 ... [Section_2] bar1=1 bar2=2 bar3=3 ... ``` If you have a serious amount of variables, it might be ...
3,434,048
I know it can be achieved by command line but I need to pass at least 10 variables and command line will mean too much of programming since these variables may or may not be passed. Actually I have build A application half in vB( for GUI ) and Half in python( for script ). I need to pass variables to python, similar, ...
2010/08/08
[ "https://Stackoverflow.com/questions/3434048", "https://Stackoverflow.com", "https://Stackoverflow.com/users/388350/" ]
Since you're working on windows with VB, it's worth mentioning that [IronPython](http://ironpython.net/) might be one option. Since both VB and IronPython can interact through .NET, you could wrap up your script in an assembly and expose a function which you call with the required arguments.
What do you think about creating a python script setting these variables from the gui side? When starting the python app you just start this script and you have your vars. [Execfile](http://docs.python.org/library/functions.html#execfile)
3,434,048
I know it can be achieved by command line but I need to pass at least 10 variables and command line will mean too much of programming since these variables may or may not be passed. Actually I have build A application half in vB( for GUI ) and Half in python( for script ). I need to pass variables to python, similar, ...
2010/08/08
[ "https://Stackoverflow.com/questions/3434048", "https://Stackoverflow.com", "https://Stackoverflow.com/users/388350/" ]
If you are using Python <2.7 I would suggest [optparse](http://docs.python.org/library/optparse.html). optparse is deprecated though, and in 2.7 you should use [argparse](http://docs.python.org/library/argparse.html#module-argparse) It makes passing named parameters a breeze.
Since you're working on windows with VB, it's worth mentioning that [IronPython](http://ironpython.net/) might be one option. Since both VB and IronPython can interact through .NET, you could wrap up your script in an assembly and expose a function which you call with the required arguments.
3,434,048
I know it can be achieved by command line but I need to pass at least 10 variables and command line will mean too much of programming since these variables may or may not be passed. Actually I have build A application half in vB( for GUI ) and Half in python( for script ). I need to pass variables to python, similar, ...
2010/08/08
[ "https://Stackoverflow.com/questions/3434048", "https://Stackoverflow.com", "https://Stackoverflow.com/users/388350/" ]
If you are using Python <2.7 I would suggest [optparse](http://docs.python.org/library/optparse.html). optparse is deprecated though, and in 2.7 you should use [argparse](http://docs.python.org/library/argparse.html#module-argparse) It makes passing named parameters a breeze.
What do you think about creating a python script setting these variables from the gui side? When starting the python app you just start this script and you have your vars. [Execfile](http://docs.python.org/library/functions.html#execfile)
5,574,649
I need a scalable `NoSql` solution to store data as *arrays* for many fields & time stamps, where the key is a combination of a `field` and a `timestamp`. Data would be stored in the following scheme: **KEY** --> "FIELD\_NAME.YYYYMMDD.HHMMSS" **VALUE** --> [v1, v2, v3, v4, v5, v6] (v1..v6 are just `floats`) For i...
2011/04/07
[ "https://Stackoverflow.com/questions/5574649", "https://Stackoverflow.com", "https://Stackoverflow.com/users/540009/" ]
Sounds like MongoDB would be a good fit. [PyMongo](http://api.mongodb.org/python/1.10+/index.html) is the api.
Your data is highly structured and regular; what benefit do you see in NoSQL vs a more traditional database? I think [MySQL Cluster](http://dev.mysql.com/downloads/cluster/) sounds tailor-made for your problem. **Edit:** @user540009: I agree that there are serious slowdowns on single-machine or mirrored instances of...
12,672,629
> > **Possible Duplicate:** > > [Converting string into datetime](https://stackoverflow.com/questions/466345/converting-string-into-datetime) > > > I am parsing an XML file that gives me the time in the respective isoformat: ``` tc1 = 2012-09-28T16:41:12.9976565 tc2 = 2012-09-28T23:57:44.6636597 ``` But it ...
2012/10/01
[ "https://Stackoverflow.com/questions/12672629", "https://Stackoverflow.com", "https://Stackoverflow.com/users/966739/" ]
You can use the [python-dateutil `parse()` function](http://labix.org/python-dateutil#head-c0e81a473b647dfa787dc11e8c69557ec2c3ecd2), it's more flexible than strptime. Hope this help you.
Use the [`datetime` module](http://docs.python.org/library/datetime.html). ``` td = datetime.strptime('2012-09-28T16:41:12.997656', '%Y-%m-%dT%H:%M:%S.%f') - datetime.strptime('2012-09-28T23:57:44.663659', '%Y-%m-%dT%H:%M:%S.%f') print td # => datetime.timedelta(-1, 60208, 333997) ``` There is only one small p...
12,672,629
> > **Possible Duplicate:** > > [Converting string into datetime](https://stackoverflow.com/questions/466345/converting-string-into-datetime) > > > I am parsing an XML file that gives me the time in the respective isoformat: ``` tc1 = 2012-09-28T16:41:12.9976565 tc2 = 2012-09-28T23:57:44.6636597 ``` But it ...
2012/10/01
[ "https://Stackoverflow.com/questions/12672629", "https://Stackoverflow.com", "https://Stackoverflow.com/users/966739/" ]
Use the [`datetime.strptime`](http://docs.python.org/library/datetime.html#strftime-strptime-behavior) method: ``` import datetime datetime.datetime.strptime(your_string, "%Y-%m-%dT%H:%M:%S.%f") ``` The link provided presents the different format directives. Note that the microseconds are limited to the range `[0,99...
Use the [`datetime` module](http://docs.python.org/library/datetime.html). ``` td = datetime.strptime('2012-09-28T16:41:12.997656', '%Y-%m-%dT%H:%M:%S.%f') - datetime.strptime('2012-09-28T23:57:44.663659', '%Y-%m-%dT%H:%M:%S.%f') print td # => datetime.timedelta(-1, 60208, 333997) ``` There is only one small p...
12,672,629
> > **Possible Duplicate:** > > [Converting string into datetime](https://stackoverflow.com/questions/466345/converting-string-into-datetime) > > > I am parsing an XML file that gives me the time in the respective isoformat: ``` tc1 = 2012-09-28T16:41:12.9976565 tc2 = 2012-09-28T23:57:44.6636597 ``` But it ...
2012/10/01
[ "https://Stackoverflow.com/questions/12672629", "https://Stackoverflow.com", "https://Stackoverflow.com/users/966739/" ]
Use the [`datetime.strptime`](http://docs.python.org/library/datetime.html#strftime-strptime-behavior) method: ``` import datetime datetime.datetime.strptime(your_string, "%Y-%m-%dT%H:%M:%S.%f") ``` The link provided presents the different format directives. Note that the microseconds are limited to the range `[0,99...
You can use the [python-dateutil `parse()` function](http://labix.org/python-dateutil#head-c0e81a473b647dfa787dc11e8c69557ec2c3ecd2), it's more flexible than strptime. Hope this help you.
42,044,619
I'm working on a project of my own, and I'm at a point where i don't know anymore what to do.. I'm trying to implement some sounds into my project where i press some tact. switches and they should make sounds.. I'm a complete newbie with python so i found a piece of code doing something similar... ``` import os from ...
2017/02/04
[ "https://Stackoverflow.com/questions/42044619", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7516655/" ]
Based on <https://github.com/Unitech/pm2/blob/master/lib/API/Extra.js#L436>, I managed to get this working Put it as the last item in your ecosystem file, and it will always have the highest id Make sure that the script path is correct, it was the default on MY system, it might not be on your I'm running 2.9.3, and ...
not sure, but you can try to specify `interpreter`. It should be your PM2 (check it with `whereis`). Try smth like `{ "apps": [{ "name": "web", "script": "", "interpreter": "/usr/local/bin/pm2", "args": "web" }] }` Please note - i didnot checked it at all, it just suggestion
63,201,965
Hi I have made my flask app and I have exposed port 5001 in Docker file. I pushed it to dockerhub repo and ran on different machine by ``` docker container run --name XYZ <username>/<repo_name>:<tag> ``` The log says that app is running on <http://127.0.0.1:5001/> But if I open that localtion in browser its says `...
2020/08/01
[ "https://Stackoverflow.com/questions/63201965", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5687866/" ]
This sounds like `insert . . . on duplicate key update`. First, though, you need a unique index or constraint: ``` create unique index unq_stocks_ticker on stocks(ticker); ``` Then you can use: ``` insert into stocks (ticker, marketcap) values (?, ?) on duplicate key update marketcap = values(marketcap); `...
An UPDATE query is incapable of creating a new row, so perhaps like: ``` UPDATE stocks SET marketcap = 300000000000 WHERE symbol = '$MMM' ``` Your footnote "unless it doesn't exist" means you probably then need to examine how many rows this altered and if it's 0 then run: ``` INSERT INTO stocks(marketcap, symbol) ...
52,458,754
I want to compare two dictionary keys in python and if the keys are equal, then print their values. For example, ``` dict_one={'12':'fariborz','13':'peter','14':'jadi'} dict_two={'15':'ronaldo','16':'messi','12':'daei','14':'jafar'} ``` and after comparing the keys, print ``` 'fariborz', 'daei' 'jadi', jafar' ```
2018/09/22
[ "https://Stackoverflow.com/questions/52458754", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9287224/" ]
You're asking for the intersection of the two dictionaries. Using the builtin type `set` ---------------------------- You can use the builtin type `set` for this, which implements the `intersection()` function. You can turn a list into a set like this: ``` set(my_list) ``` So, in order to find the intersection be...
``` for key, val1 in dict_one.items(): val2 = dict_two.get(key) if val2 is not None: print(val1, val2) ```
52,458,754
I want to compare two dictionary keys in python and if the keys are equal, then print their values. For example, ``` dict_one={'12':'fariborz','13':'peter','14':'jadi'} dict_two={'15':'ronaldo','16':'messi','12':'daei','14':'jafar'} ``` and after comparing the keys, print ``` 'fariborz', 'daei' 'jadi', jafar' ```
2018/09/22
[ "https://Stackoverflow.com/questions/52458754", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9287224/" ]
You can iterate over the intersection of the keys of the two dicts, and print the corresponding values of the two dicts after mapping them to the `repr` function, which would help quote the strings: ``` for k in dict_one.keys() & dict_two.keys(): print(','.join(map(repr, (dict_one[k], dict_two[k])))) ``` This ou...
``` def compare(dict1,dict2): keys1 = dict1.keys() keys2 = dict2.keys() for key in keys1: if key in keys: print(dict1[key],dict2[key]) ```
52,458,754
I want to compare two dictionary keys in python and if the keys are equal, then print their values. For example, ``` dict_one={'12':'fariborz','13':'peter','14':'jadi'} dict_two={'15':'ronaldo','16':'messi','12':'daei','14':'jafar'} ``` and after comparing the keys, print ``` 'fariborz', 'daei' 'jadi', jafar' ```
2018/09/22
[ "https://Stackoverflow.com/questions/52458754", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9287224/" ]
You can iterate over the intersection of the keys of the two dicts, and print the corresponding values of the two dicts after mapping them to the `repr` function, which would help quote the strings: ``` for k in dict_one.keys() & dict_two.keys(): print(','.join(map(repr, (dict_one[k], dict_two[k])))) ``` This ou...
``` for key, val1 in dict_one.items(): val2 = dict_two.get(key) if val2 is not None: print(val1, val2) ```
52,458,754
I want to compare two dictionary keys in python and if the keys are equal, then print their values. For example, ``` dict_one={'12':'fariborz','13':'peter','14':'jadi'} dict_two={'15':'ronaldo','16':'messi','12':'daei','14':'jafar'} ``` and after comparing the keys, print ``` 'fariborz', 'daei' 'jadi', jafar' ```
2018/09/22
[ "https://Stackoverflow.com/questions/52458754", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9287224/" ]
You can use the `&` operator with to find the matching keys ``` for i in d1.keys() & d2.keys(): print("'{}', '{}'".format(d1[i], d2[i])) ``` > > > ``` > ~/python/stack/sept/twenty_2$ python3.7 alice.py > 'fariborz', 'daei' > 'jadi', 'jafar > > ``` > >
Dictionaries are nice in python because they allow us to look up a key's value very easily and also check if a key exists in the dict. So in your example if you want to print the values for whenever the keys are the same between the dicts you can do something like this: ``` dict_one={'12':'fariborz','13':'peter','14'...
52,458,754
I want to compare two dictionary keys in python and if the keys are equal, then print their values. For example, ``` dict_one={'12':'fariborz','13':'peter','14':'jadi'} dict_two={'15':'ronaldo','16':'messi','12':'daei','14':'jafar'} ``` and after comparing the keys, print ``` 'fariborz', 'daei' 'jadi', jafar' ```
2018/09/22
[ "https://Stackoverflow.com/questions/52458754", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9287224/" ]
You can use the `&` operator with to find the matching keys ``` for i in d1.keys() & d2.keys(): print("'{}', '{}'".format(d1[i], d2[i])) ``` > > > ``` > ~/python/stack/sept/twenty_2$ python3.7 alice.py > 'fariborz', 'daei' > 'jadi', 'jafar > > ``` > >
Using intersection .then you can get the same key value from `dict_one` and `dict_two` This is my code: ``` dict_one={'12':'fariborz','13':'peter','14':'jadi'} dict_two={'15':'ronaldo','16':'messi','12':'daei','14':'jafar'} print([(dict_one[vals],dict_two[vals]) for vals in dict_one.keys() & dict_two.keys()]) ``` O...
52,458,754
I want to compare two dictionary keys in python and if the keys are equal, then print their values. For example, ``` dict_one={'12':'fariborz','13':'peter','14':'jadi'} dict_two={'15':'ronaldo','16':'messi','12':'daei','14':'jafar'} ``` and after comparing the keys, print ``` 'fariborz', 'daei' 'jadi', jafar' ```
2018/09/22
[ "https://Stackoverflow.com/questions/52458754", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9287224/" ]
You can use the `&` operator with to find the matching keys ``` for i in d1.keys() & d2.keys(): print("'{}', '{}'".format(d1[i], d2[i])) ``` > > > ``` > ~/python/stack/sept/twenty_2$ python3.7 alice.py > 'fariborz', 'daei' > 'jadi', 'jafar > > ``` > >
Take iteration through one dictionary and check for existence of key in the other: ``` dict_one = {'12':'fariborz','13':'peter','14':'jadi'} dict_two = {'15':'ronaldo','16':'messi','12':'daei','14':'jafar'} for k in dict_one: if k in dict_two: print(dict_one[k], dict_two[k]) # fariborz daei # jadi jafar ...
52,458,754
I want to compare two dictionary keys in python and if the keys are equal, then print their values. For example, ``` dict_one={'12':'fariborz','13':'peter','14':'jadi'} dict_two={'15':'ronaldo','16':'messi','12':'daei','14':'jafar'} ``` and after comparing the keys, print ``` 'fariborz', 'daei' 'jadi', jafar' ```
2018/09/22
[ "https://Stackoverflow.com/questions/52458754", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9287224/" ]
You can use the `&` operator with to find the matching keys ``` for i in d1.keys() & d2.keys(): print("'{}', '{}'".format(d1[i], d2[i])) ``` > > > ``` > ~/python/stack/sept/twenty_2$ python3.7 alice.py > 'fariborz', 'daei' > 'jadi', 'jafar > > ``` > >
``` def compare(dict1,dict2): keys1 = dict1.keys() keys2 = dict2.keys() for key in keys1: if key in keys: print(dict1[key],dict2[key]) ```
52,458,754
I want to compare two dictionary keys in python and if the keys are equal, then print their values. For example, ``` dict_one={'12':'fariborz','13':'peter','14':'jadi'} dict_two={'15':'ronaldo','16':'messi','12':'daei','14':'jafar'} ``` and after comparing the keys, print ``` 'fariborz', 'daei' 'jadi', jafar' ```
2018/09/22
[ "https://Stackoverflow.com/questions/52458754", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9287224/" ]
You can iterate over the intersection of the keys of the two dicts, and print the corresponding values of the two dicts after mapping them to the `repr` function, which would help quote the strings: ``` for k in dict_one.keys() & dict_two.keys(): print(','.join(map(repr, (dict_one[k], dict_two[k])))) ``` This ou...
Using intersection .then you can get the same key value from `dict_one` and `dict_two` This is my code: ``` dict_one={'12':'fariborz','13':'peter','14':'jadi'} dict_two={'15':'ronaldo','16':'messi','12':'daei','14':'jafar'} print([(dict_one[vals],dict_two[vals]) for vals in dict_one.keys() & dict_two.keys()]) ``` O...
52,458,754
I want to compare two dictionary keys in python and if the keys are equal, then print their values. For example, ``` dict_one={'12':'fariborz','13':'peter','14':'jadi'} dict_two={'15':'ronaldo','16':'messi','12':'daei','14':'jafar'} ``` and after comparing the keys, print ``` 'fariborz', 'daei' 'jadi', jafar' ```
2018/09/22
[ "https://Stackoverflow.com/questions/52458754", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9287224/" ]
You're asking for the intersection of the two dictionaries. Using the builtin type `set` ---------------------------- You can use the builtin type `set` for this, which implements the `intersection()` function. You can turn a list into a set like this: ``` set(my_list) ``` So, in order to find the intersection be...
Dictionaries are nice in python because they allow us to look up a key's value very easily and also check if a key exists in the dict. So in your example if you want to print the values for whenever the keys are the same between the dicts you can do something like this: ``` dict_one={'12':'fariborz','13':'peter','14'...
52,458,754
I want to compare two dictionary keys in python and if the keys are equal, then print their values. For example, ``` dict_one={'12':'fariborz','13':'peter','14':'jadi'} dict_two={'15':'ronaldo','16':'messi','12':'daei','14':'jafar'} ``` and after comparing the keys, print ``` 'fariborz', 'daei' 'jadi', jafar' ```
2018/09/22
[ "https://Stackoverflow.com/questions/52458754", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9287224/" ]
You're asking for the intersection of the two dictionaries. Using the builtin type `set` ---------------------------- You can use the builtin type `set` for this, which implements the `intersection()` function. You can turn a list into a set like this: ``` set(my_list) ``` So, in order to find the intersection be...
Take iteration through one dictionary and check for existence of key in the other: ``` dict_one = {'12':'fariborz','13':'peter','14':'jadi'} dict_two = {'15':'ronaldo','16':'messi','12':'daei','14':'jafar'} for k in dict_one: if k in dict_two: print(dict_one[k], dict_two[k]) # fariborz daei # jadi jafar ...
68,425,073
I have a list like this: ``` list1 = ['hello', 'halo', 'goodbye', 'bye bye', 'how are you?'] ``` I want for example to replace ‘hello’ and ‘halo’ with ‘welcome’, and ‘goodbye’ and ‘bye bye’ with ‘greetings’ so the list will be like this: ``` list1 or newlist = ['welcome', 'welcome', 'greetings', 'greetings', 'how a...
2021/07/17
[ "https://Stackoverflow.com/questions/68425073", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16431450/" ]
if the substitutions can easily be grouped then this works: ```py list1 = ['hello', 'halo', 'goodbye', 'bye bye', 'how are you?'] new_list = [] group1 = ('hello', 'halo') group2 = ('goodbye', 'bye bye') for word in list1: if word in group1: new_list.append('welcome') elif word in group2: new_l...
I see this question is marked with the re tag, so I will answer using regular expressions. You can replace text using re.sub. ``` >>> import re >>> list1 = ",".join(['hello', 'halo', 'goodbye', 'bye bye', 'how are you?']) >>> list1 = re.sub(r"hello|halo", r"welcome", list1) >>> list1 = re.sub(r"goodbye|bye bye", r"gre...
68,425,073
I have a list like this: ``` list1 = ['hello', 'halo', 'goodbye', 'bye bye', 'how are you?'] ``` I want for example to replace ‘hello’ and ‘halo’ with ‘welcome’, and ‘goodbye’ and ‘bye bye’ with ‘greetings’ so the list will be like this: ``` list1 or newlist = ['welcome', 'welcome', 'greetings', 'greetings', 'how a...
2021/07/17
[ "https://Stackoverflow.com/questions/68425073", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16431450/" ]
if the substitutions can easily be grouped then this works: ```py list1 = ['hello', 'halo', 'goodbye', 'bye bye', 'how are you?'] new_list = [] group1 = ('hello', 'halo') group2 = ('goodbye', 'bye bye') for word in list1: if word in group1: new_list.append('welcome') elif word in group2: new_l...
List comprehension would be the shortest way... ``` list1 = ['hello', 'halo', 'goodbye', 'bye bye', 'how are you?'] newlist = ['welcome' if i == 'hello' or i == 'halo' else 'greetings' if i == 'goodbye' or i == 'bye bye' else i for i in list1 ] print(newlist) ```
14,976,968
I am trying to run a c++ program from python. My problem is that everytime i run: ``` subprocess.Popen(['sampleprog.exe'], stdin = iterate, stdout = myFile) ``` it only reads the first line in the file. Every time I enclose it with a while loop it ends up crushing because of the infinite loop. Is there any other way...
2013/02/20
[ "https://Stackoverflow.com/questions/14976968", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2090597/" ]
Your line of code ``` 10 open (23,file=outfile,status='old',access='append',err=10) ``` specifies that the `open` statement should transfer control to itself (label 10) in case an error is encountered, so any error could trigger an infinite loop. It also suppresses the output of error messages. If you want to just c...
The `err=` argument in your `open` statement specifies a statement label to branch to should the `open` fail for some reason. Your code specifies a branch to the line labelled `10` which happens to be the line containing the `open` statement. This is probably not a good idea; a better idea would be to branch to a line ...
47,959,991
I have gathered obligatory data from the scopus website. my outputs have been saved in a list named "document". when I use type method for each element of this list, the python returns me this class: ``` "<class'selenium.webdriver.firefox.webelement.FirefoxWebElement'>" ``` In continius in order to solve this issu...
2017/12/24
[ "https://Stackoverflow.com/questions/47959991", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8461493/" ]
As you have used the following line of code : ``` document=driver.find_elements_by_tag_name('td') ``` and see the output on Console as : ``` "<class'selenium.webdriver.firefox.webelement.FirefoxWebElement'>" ``` This is the expected behavior as **`Selenium`** prints the reference of the **`Nodes`** matching your...
My code was correct. But, the selected elements for displaying were space. By select another element, the result was shown.