I am working on a Python script to search for bluetooth devices and connect them using RFCOMM. This devices has Passkey/Password. I am using PyBlueZ and, as far as I know, this library cannot handle Passkey/Password connections (Python PyBluez connecting to passkey protected device). I am able to discover the…
Tag: python
Python: search for a file in current directory and all it’s parents
Is there an inbuilt module to search for a file in the current directory, as well as all the super-directories? Without the module, I’ll have to list all the files in the current directory, search for the file in question, and recursively move up if the file isn’t present. Is there an easier way t…
Python bindings for libVLC – cannot change audio output device
VLC 2.2.3, python-vlc 1.1.2. I have a virtual audio output and am trying to get libVLC to output on it. So far, I can see the virtual output appearing in libVLC, but selecting it makes audio play on the default output (i.e. the speakers). This is the relevant part of what I have: I’ve run the code multi…
How can I read in a binary file from hdfs into a Spark dataframe?
I am trying to port some code from pandas to (py)Spark. Unfortunately I am already failing with the input part, where I want to read in binary data and put it in a Spark Dataframe. So far I am using fromfile from numpy: But for Spark I couldn’t find how to do it. My workaround so far was to use
yaml anchors definitions loading in PyYAML
I’m using PyYAML. Is there a way to define a YAML anchor in a way it won’t be a part of the data structure loaded by yaml.load (I can remove “wifi_parm” from the dictionary but looking for a smarter way)? example.yaml: load_example.py: prints: I need: Answer The anchor information in P…
Get data points from Seaborn distplot
I use to plot a univariate distribution of observations. Still, I need not only the chart, but also the data points. How do I get the data points from matplotlib Axes (returned by distplot)? Answer You can use the matplotlib.patches API. For instance, to get the first line: This returns two numpy arrays conta…
Is it possible to use argparse to capture an arbitrary set of optional arguments?
Is it possible to use argparse to capture an arbitrary set of optional arguments? For example both the following should be accepted as inputs: a priori I don’t know what optional arguments would be specified receive but would handle them accordingly. Answer This is kind of a hackish way, but it works we…
Django model DateTimeField set auto_now_add format or modify the serializer
I have this field in my model: And it is saved with this format: 2016-05-18T15:37:36.993048Z So I would like to convert it to this format DATE_INPUT_FORMATS = (‘%d-%m-%Y %H:%M:S’) but I dont know where to do it. I have a simple serializer class, could I override it to modify the format? or maybe c…
putting file names in an array using os in python
I want to create a program that will use os to make an ls of a directory and then put the files in a array. However, ls does not list the names one by one, so I am kind of stuck, because there’s nothing constant by which I can tell when the next name starts. Here is the actual code:
Mock timing in a context to create models with a field DateTimeField with auto_now_add=True
I’d like to mock timing so that be able to set certain time to a field of type DateTimeField with auto_now_add=True during my tests e.g: I’m aware the current date is always used for this type of fields, that is why I’m looking for an alternative to mock somehow the system timing, but just i…