I don't quite understand why no results are returned when the value is empty. Is there a way to get the key value pair when the value is empty? Thanks.
>>> urllib.parse.parse_qsl('a=b')
[('a', 'b')]
>>> urllib.parse.parse_qsl('a=')
[]
You can use keep_blank_values parameter. By the way, what version of python are you using. This is what I get when I use the keep_blank_values. By default it is set to False. And I use python version 3.8.2
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib.parse import parse_qsl
>>> parse_qsl('a=b')
[('a', 'b')]
>>> parse_qsl('a=')
[]
>>> parse_qsl('a=', keep_blank_values=True)
[('a', '')]
>>>
Related
I don't have an M1 Mac to work with, I read that python supports it. What's the return of these functions on m1 Macs?
platform.system()
platform.architecture()
Thanks.
On the actual M1 Mac, the platform module returns the following values:
shuuji3#momo ~ % python3
Python 3.8.2 (default, Dec 21 2020, 15:06:03)
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.platform()
'macOS-11.2.3-arm64-arm-64bit'
>>> platform.system()
'Darwin'
>>> platform.architecture()
('64bit', '')
>>> platform.processor()
'arm'
In addition to that, under the Rosetta 2 (Intel mode), the platform module returns the different values like followings:
shuuji3#momo ~ % env /usr/bin/arch -x86_64 /bin/zsh --login
shuuji3#momo ~ % python3
Python 3.8.2 (default, Dec 21 2020, 15:06:04)
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.platform()
'macOS-11.2.3-x86_64-i386-64bit'
>>> platform.system()
'Darwin'
>>> platform.architecture()
('64bit', '')
>>> platform.processor()
'i386'
Note: For the first command, I'm following the instruction in the article, How to Run Legacy Command Line Apps on Apple Silicon | Walled Garden Farmers.
We could use these values to distinguish under which mode the current M1 mac runs an application.
I got an M1 pro and the outputs are:
Python 3.8.15 (default, Nov 10 2022, 13:17:42)
[Clang 14.0.6 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more
information.
>>> import platform
>>> platform.platform()
'macOS-10.16-x86_64-i386-64bit'
>>> platform.system()
'Darwin'
If my file name is 5f0756fa-75bc-4c70-9ba8-fbd1b6a9f843_20200616T10_50_UTC.wav .. Output to be 5f0756fa-75bc-4c70-9ba8-fbd1b6a9f843.wav . How can we trim the file name using python?
There are several ways to do, for instance
import os
l=os.path.splitext("5f0756fa-75bc-4c70-9ba8-fbd1b6a9f843_20200616T10_50_UTC.wav")
l[0].split("_")[0] + l[1]
I use os.path.splitext to separate the possible extension
Execution with and without '_' and with and without extension :
pi#raspberrypi:~ $ python3
Python 3.7.3 (default, Dec 20 2019, 18:57:59)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>>
>>> def f(s):
... l = os.path.splitext(s)
... return l[0].split("_")[0] + l[1]
...
>>> f("5f0756fa-75bc-4c70-9ba8-fbd1b6a9f843_20200616T10_50_UTC.wav")
'5f0756fa-75bc-4c70-9ba8-fbd1b6a9f843.wav'
>>>
>>> f("5f0756fa-75bc-4c70-9ba8-fbd1b6a9f843.wav")
'5f0756fa-75bc-4c70-9ba8-fbd1b6a9f843.wav'
>>>
>>> f("5f0756fa-75bc-4c70-9ba8-fbd1b6a9f843_20200616T10_50_UTC")
'5f0756fa-75bc-4c70-9ba8-fbd1b6a9f843'
>>>
>>> f("5f0756fa-75bc-4c70-9ba8-fbd1b6a9f843")
'5f0756fa-75bc-4c70-9ba8-fbd1b6a9f843'
>>>
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import boto3
>>> import json
>>> import gzip
>>> import time
>>> from io import StringIO
>>> from base64 import b64decode
>>> import io
>>>
>>>
>>> orig_str = 'H4sIAAAAAAAAAL3U3WvbMBAA8H9F6Dk29yGdpL6FLO3DGCsk7GWUkaVKMeTD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\x8bm\x1a\xed\xd5\xb6\xf1\xf8.\xaf\xbb_k\x1elu\xad\xfd\xd9\x138\x9f\\\x00I\x8c\x00\xce1k\xe4\x99#9&\x94H\xac\x97Hz\x1bQ\x82\x06\x12]\x04\xdd\xbb\xab\xd4\xdd\xcdVJ#\x1f\xa2h\x85\x1c\x00\x0c\x9e\xdf\x87\xb6\'\xb3\xcf6\x075\x06QJ\x91\x12\x05K1\x18\xa8d,1\x96\xe8\xd9 \xb1q#\x124o\xd0\x04\xad\xbfl\xf5\x12F6\xc3\xd1h|95\x9f?\xda\xc7\xc1\xff\xc9\xb0W\xd9k\xcc\xbes\xa7R\xdf\xa9d\xd4\xab\x0c\xb8\x0cR:(\x9f\x08\xbf\x0f\xcd\x13\xa7\xd3\xd1\xf8\x88C{\x05\xdd\xb1\xde=5\x01 \x0e\x1e}D\x16I\x14#\x04J\xe41$\xcd\xe8cH\x10\xa7\xaa\x94\x12\t\xb0\xb8\xe8\x0e\xd2b\xa0\xfei>\xe0!\x9a\xee\xf5\x1c&\xea\x93\xe6{\xa5\xfd\xfd\x10\xf1\x89\xc2\x1f\x87\xc8\xd1d\xd2\xab\xec\x9f\xbf\xdavp\'\xa2\x85#~\x8f\xfb#\xdc\r\xec-\x9f\xe3\xd5\xe3O\x023i\x00\x8b\x07\x00\x00'
>>>
>>>
The output was on bytes, while I wanted this to be the text/string; should look something like this,
2 074939084796 eni-0d882207508141cd4 432.150.28.36 352.67.89.12 123 52782 17 1 76 1578627847 1578627896 ACCEPT OK
I just finished installing Tensorflow 1.3 on RPi 3. When validating the installation (according to this https://www.tensorflow.org/install/install_sources) somehow a lowercase "b" shown up. See these codes:
root#raspberrypi:/home/pi# python
Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
b'Hello, TensorFlow!'
>>>
No, it's not a bug. Your installation is perfectly fine, this is the normal behavior.
The b before the string is due to the Tensorflow internal representation of strings.
Tensorflow represents strings as byte array, thus when you "extract" them (from the graph, thus tensorflow's internal representation, to the python enviroment) using sess.run(hello) you get a bytes type and not a str type.
You can verify this using the type function:
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(type(sess.run(hello)))
results in <class 'bytes'> whilst if you do:
print(type('Hello, TensorFlow!'))
results in <class 'str'>
The following is a snippet from my Python 3.5 interpreter. I don't understand why this produces the error (Listed bellow). Any suggestions?
Python 3.5.3 (v3.5.3:1880cb95a742, Jan 16 2017, 16:02:32) [MSC v.1900 64
bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, Tensorflow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
Then it gives me just a list of internal Errors starting with:
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943]