Python ValueError: embedded null byte when reading png file from bash pipe
Try first to load raw data into a BytesIO
container:
from io import BytesIO
from PIL import Image
from subprocess import Popen, PIPE
data = Popen.communicate(Popen(['import','-w','0x02a00001','png:-'], stdout=PIPE))[0]
scr = Image.open(BytesIO(data))
Mysterious embedded null byte error
- One of the
AppConfig
objects has null byte in itspath
attribute. - One of the
LOCALE_PATHS
has null byte. - One of the files is in the "wrong" encoding, so Django treats something has null byte (e. g.
AppConfig.path
). - One of the files or directories in project directory has null byte (
\x00
) in its name. - Other reason.
autoreload.py
lines related to this issue. os.path.isdir()
raises ValueError: embedded null byte
if its argument has null byte, e. g. os.path.isdir('foo\x00bar')
.
You can try to edit autoreload.py
, comment out these lines temporarily:
basedirs = [os.path.abspath(basedir) for basedir in basedirs
if os.path.isdir(basedir)]
and add this:
temp_basedirs = []
for basedir in basedirs:
try:
if os.path.isdir(basedir):
temp_basedirs.append(os.path.abspath(basedir))
except ValueError:
print(basedir)
raise
basedirs = temp_basedirs
Find number of concurrent users in a SQL records
Clearly the number of concurrent users only changes when a user either starts or ends a period, so it is enough to determine the number of concurrent users during starts and ends. So, reusing test data provided by Remus (thank you Remus):
DECLARE @Table TABLE
(
UserId int,
StartedOn datetime,
EndedOn datetime
);
insert into @table (UserId, startedOn, EndedOn)
select 1, '2009-7-12 14:01', '2009-7-12 15:01'
union all select 2, '2009-7-12 14:30', '2009-7-12 14:45'
union all select 3, '2009-7-12 14:47', '2009-7-12 15:30'
union all select 4, '2009-7-12 13:01', '2009-7-12 17:01'
union all select 5, '2009-7-12 14:15', '2009-7-12 18:01'
union all select 6, '2009-7-12 11:01', '2009-7-12 19:01'
union all select 1, '2009-7-12 16:07', '2009-7-12 19:01';
SELECT MAX(ConcurrentUsers) FROM(
SELECT COUNT(*) AS ConcurrentUsers FROM @table AS Sessions
JOIN
(SELECT DISTINCT StartedOn AS ChangeTime FROM @table
) AS ChangeTimes
ON ChangeTime >= StartedOn AND ChangeTime < EndedOn
GROUP BY ChangeTime
) AS ConcurrencyAtChangeTimes
-------
5
BTW using DISTINCT per se is not a mistake - only abusing DISTINCT is. DISTINCT is just a tool, using it in this context is perfectly correct.
Edit: I was answering the OP's question: "how one could calculate this using T-SQL only".
Note that the question does not mention performance.
If the questions was this: "what is the fastest way to determine maximum concurrency if the data is stored in SQL Server", I would provide a different answer, something like this:
Consider the following alternatives
- Write a cursor
- Write a CLR cursor
- Write a loop on the client
- Use an RDBMS with decent cursors, such as Oracle or PostgreSql
- For top performance, design your table differently, so that you can retrieve the answer in one index seek. This is what I do in my system if I need to deliver best possible performance.
If the question was "what is the fastest way to determine maximum concurrency using a T-SQL query", I would probably not answer at all. The reason: if I needed really good performance, I would not solve this problem in a T-SQL query.
Line contains NULL byte in CSV reader (Python)
I've solved a similar problem with an easier solution:
import codecs
csvReader = csv.reader(codecs.open('file.csv', 'rU', 'utf-16'))
The key was using the codecs module to open the file with the UTF-16 encoding, there are a lot more of encodings, check the documentation.
Related Topics
Binding Callbacks to Minimize and Maximize Events in Toplevel Windows
Run a Process to /Dev/Null in Python
Multiprocessing Module Showing Memory for Each Child Process Same as Main Process
How Would a Python Script Running on Linux Call a Routine in a Python Script Running Under Wine
What Are the Tkinter Events for Horizontal Edge Scrolling (In Linux)
Maltparser Giving Error in Nltk
A Simple Python Deployment Problem - a Whole World of Pain
Kill Python Interpeter in Linux from the Terminal
Differencebetween C.Utf-8 and En_Us.Utf-8 Locales
Capturing Output of Python Script Run Inside a Docker Container
How to Default Python3.8 on My MAC Using Homebrew
How to Delete a Directory Created with Tempfile.Mkdtemp
How to Deal with Linux/Python Dependencies
Increasing a File's Size Using Mmap
Interfacing Python and Torch7(Lua) via Shared Library
How to Call a Parent Class'S Method from a Child Class in Python