Re: issue in handling CSV data

2019-09-08 Thread Andrea D'Amore
On Sun, 8 Sep 2019 at 02:19, Sharan Basappa  wrote:
 This is the error:
> my_data_3 = my_data_2.astype(np.float)
> could not convert string to float: " "81

> As you can see, the string "\t"81 is causing the error.
> It seems to be due to char "\t".

It is not clear what format do you expect to be in the file.
You say "it is CSV" so your actual payload seems to be a pair of three
bytes (a tab and two hex digits in ASCII) per line.

Can you paste a hexdump of the first three lines of the input file and
say what you expect to get once the data has been processed?


-- 
Andrea
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is it 'fine' to instantiate a widget without parent parameter?

2019-09-08 Thread Terry Reedy

On 9/7/2019 9:44 PM, jf...@ms4.hinet.net wrote:

I know it is valid, according to the Tkinter source, every widget constructor 
has a 'master=None' default. What happens on doing this?


Tkinter creates a default Tk object and uses that as the master.

>>> t = tkinter.Text()
>>> t.master



In what circumstance, we do it this way? and will it cause any trouble?


I believe it is OK if you always do it that way within a single 
application.  But I prefer to have an explicit reference and use that 
for .after calls and some others.



--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


local variable 'p' referenced before assignment

2019-09-08 Thread Pankaj Jangid
Why this code is giving local variable access error when I am accessing
a global variable?

p = 0
def visit():
m = 1
if m > p:
p = m

visit()
print(p)

If I change the variable assignment inside the function to q = m then it
works fine. Like this

p = 0
def visit():
m = 1
if m > p:
q = m# Changed 'p' to 'q'

visit()
print(p)

-- 
Pankaj Jangid
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: local variable 'p' referenced before assignment

2019-09-08 Thread David
On Sun, 8 Sep 2019 at 19:55, Pankaj Jangid  wrote:
>
> Why this code is giving local variable access error when I am accessing
> a global variable?

> p = 0
> def visit():
>m = 1
>if m > p:
>p = m

https://docs.python.org/3/faq/programming.html#what-are-the-rules-for-local-and-global-variables-in-python

" If a variable is assigned a value anywhere within the function’s body,
it’s assumed to be a local unless explicitly declared as global."

So to avoid causing this error, inside your function you must
explicitly declare p as global before you try to assign to it.

Inside your function, you need a statement:
global p
before you try to assign to p.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is it 'fine' to instantiate a widget without parent parameter?

2019-09-08 Thread jfong
Terry Reedy於 2019年9月8日星期日 UTC+8下午5時31分34秒寫道:
> On 9/7/2019 9:44 PM, jf...@ms4.hinet.net wrote:
> > I know it is valid, according to the Tkinter source, every widget 
> > constructor has a 'master=None' default. What happens on doing this?
> 
> Tkinter creates a default Tk object and uses that as the master.
> 
>  >>> t = tkinter.Text()
>  >>> t.master
> 
> 
> > In what circumstance, we do it this way? and will it cause any trouble?
> 
> I believe it is OK if you always do it that way within a single 
> application.  But I prefer to have an explicit reference and use that 
> for .after calls and some others.
> 
> 
> -- 
> Terry Jan Reedy

If I have two widgets created this way:
t0 = tkinter.Text()
t1 = tkinter.Text()
How many Tk objects will there be?

--Jach
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is it 'fine' to instantiate a widget without parent parameter?

2019-09-08 Thread David
On Sun, 8 Sep 2019 at 20:25,  wrote:
>
> If I have two widgets created this way:
> t0 = tkinter.Text()
> t1 = tkinter.Text()
> How many Tk objects will there be?

$ python3
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> t0 = tkinter.Text()
>>> t1 = tkinter.Text()
>>> t0 is t1
False
>>> t0

>>> t1

>>>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is it 'fine' to instantiate a widget without parent parameter?

2019-09-08 Thread jfong
David於 2019年9月8日星期日 UTC+8下午6時44分55秒寫道:
> On Sun, 8 Sep 2019 at 20:25,  wrote:
> >
> > If I have two widgets created this way:
> > t0 = tkinter.Text()
> > t1 = tkinter.Text()
> > How many Tk objects will there be?
> 
> $ python3
> Python 3.5.3 (default, Sep 27 2018, 17:25:39)
> [GCC 6.3.0 20170516] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import tkinter
> >>> t0 = tkinter.Text()
> >>> t1 = tkinter.Text()
> >>> t0 is t1
> False
> >>> t0
> 
> >>> t1
> 
> >>>

Sorry, didn't make it clear. I mean  

--Jach
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is it 'fine' to instantiate a widget without parent parameter?

2019-09-08 Thread David
On Sun, 8 Sep 2019 at 21:05,  wrote:
> David於 2019年9月8日星期日 UTC+8下午6時44分55秒寫道:
> > On Sun, 8 Sep 2019 at 20:25,  wrote:

> > > If I have two widgets created this way:
> > > t0 = tkinter.Text()
> > > t1 = tkinter.Text()
> > > How many Tk objects will there be?

> Sorry, didn't make it clear. I mean 

Sorry I didn't read more carefully.
But I think that the method I demonstrated can give
the answer to your question.

>>> import tkinter
>>> t0 = tkinter.Text()
>>> t1 = tkinter.Text()
>>> t0.master

>>> t1.master

>>> t0.master is t1.master
True
>>>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: issue in handling CSV data

2019-09-08 Thread Sharan Basappa
On Sunday, 8 September 2019 04:56:29 UTC-4, Andrea D'Amore  wrote:
> On Sun, 8 Sep 2019 at 02:19, Sharan Basappa  wrote:
>  This is the error:
> > my_data_3 = my_data_2.astype(np.float)
> > could not convert string to float: " "81
> 
> > As you can see, the string "\t"81 is causing the error.
> > It seems to be due to char "\t".
> 
> It is not clear what format do you expect to be in the file.
> You say "it is CSV" so your actual payload seems to be a pair of three
> bytes (a tab and two hex digits in ASCII) per line.
> 
> Can you paste a hexdump of the first three lines of the input file and
> say what you expect to get once the data has been processed?

Andrea,

The issue seems to be presence of tabs along with the numbers in a single 
string. So, when I try to convert strings to numbers, it fails due to presence 
of tabs.

Here is the hex dump:

22 61 64 64 72 65 73 73 2c 22 09 22 6c 65 6e 67 
74 68 2c 22 09 22 38 31 2c 22 09 35 63 0d 0a 22 
61 64 64 72 65 73 73 2c 22 09 22 6c 65 6e 67 74 
68 2c 22 09 22 30 34 2c 22 09 31 31 0d 0a 22 61 
64 64 72 65 73 73 2c 22 09 22 6c 65 6e 67 74 68 
2c 22 09 22 65 31 2c 22 09 31 37 0d 0a 22 61 64 
64 72 65 73 73 2c 22 09 22 6c 65 6e 67 74 68 2c 
22 09 22 36 61 2c 22 09 36 63 0d 0a 22 61 64 64 
72 65 73 73 2c 22 09 22 6c 65 6e 67 74 68 2c 22 
09 22 35 33 2c 22 09 36 39 0d 0a 22 61 64 64 72 
65 73 73 2c 22 09 22 6c 65 6e 67 74 68 2c 22 09 
22 39 38 2c 22 09 38 37 0d 0a 22 61 64 64 72 65 
73 73 2c 22 09 22 6c 65 6e 67 74 68 2c 22 09 22 
35 63 2c 22 09 34 62 0d 0a 22 61 64 64 72 65 73 
73 2c 22 09 22 6c 65 6e 67 74 68 2c 22 09 22 32 
38 2c 22 09 33 36 0d 0a 22 61 64 64 72 65 73 73 
2c 22 09 22 6c 65 6e 67 74 68 2c 22 09 22 36 33 
2c 22 09 35 30 0d 0a 22 61 64 64 72 65 73 73 2c 
22 09 22 6c 65 6e 67 74 68 2c 22 09 22 32 34 2c 
22 09 32 31 0d 0a 22 61 64 64 72 65 73 73 2c 22 
09 22 6c 65 6e 67 74 68 2c 22 09 22 64 66 2c 22 
09 39 61 0d 0a 22 61 64 64 72 65 73 73 2c 22 09 
22 6c 65 6e 67 74 68 2c 22 09 22 61 62 2c 22 09 
62 39 0d 0a 22 61 64 64 72 65 73 73 2c 22 09 22 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 3 cubes that sum to 42

2019-09-08 Thread Michael F. Stemper
On 07/09/2019 19.12, Terry Reedy wrote:
 (-80538738812075974)**3 + 80435758145817515**3 +
> 12602123297335631**3 == 42
> True  # Impressively quickly, in a blink of an eye.

Yeah. When I saw the video, I tried it as well. Python's arbitrary-sized
integer arithmetic is truly amazing!

In fact, I ended up writing a tiny program to cube its arguments and
report the sum. Took about 40 ms to run, no matter the size of the
arguments, which tells me that the only cost is the fixed overhead.

-- 
Michael F. Stemper
This sentence no verb.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 3 cubes that sum to 42

2019-09-08 Thread אורי
I tried to add one:

>>> (-80538738812075975)**3 + 80435758145817515**3 + 12602123297335631**3
-19459465348319378856503251080373909

אורי
u...@speedy.net


On Sun, Sep 8, 2019 at 3:14 AM Terry Reedy  wrote:

>  >>> (-80538738812075974)**3 + 80435758145817515**3 +
> 12602123297335631**3 == 42
> True  # Impressively quickly, in a blink of an eye.
>
> This is the last number < 100, not theoretically excluded, to be solved.
>   Compute power provided by CharityEngine.  For more, see Numberphile...
> https://www.youtube.com/watch?v=zyG8Vlw5aAw
>
> --
> Terry Jan Reedy
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


numpy array - convert hex to int

2019-09-08 Thread Sharan Basappa
I have a numpy array that has data in the form of hex.
I would like to convert that into decimal/integer.
Need suggestions please.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: numpy array - convert hex to int

2019-09-08 Thread Luciano Ramalho
>>> int('C0FFEE', 16)
12648430

There you go!

On Sun, Sep 8, 2019 at 12:02 PM Sharan Basappa  wrote:
>
> I have a numpy array that has data in the form of hex.
> I would like to convert that into decimal/integer.
> Need suggestions please.
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Luciano Ramalho
|  Author of Fluent Python (O'Reilly, 2015)
| http://shop.oreilly.com/product/0636920032519.do
|  Technical Principal at ThoughtWorks
|  Twitter: @ramalhoorg
-- 
https://mail.python.org/mailman/listinfo/python-list


Finding lines in .txt file that contain keywords from two different set()

2019-09-08 Thread A S
My problem is seemingly profound but I hope to make it sound as simplified as 
possible.Let me unpack the details..:

1. I have one folder of Excel (.xlsx) files that serve as a data dictionary.

-In Cell A1, the data source name is written in between brackets

-In Cols C:D, it contains the data field names (It could be in either col C or 
D in my actual Excel sheet. So I had to search both columns

-*Important: I need to know which data source the field names come from

2. I have another folder of Text (.txt) files that I need to parse through to 
find these keywords.

These are the folders used for a better reference ( 
https://drive.google.com/open?id=1_LcceqcDhHnWW3Nrnwf5RkXPcnDfesq ). The files 
are found in the folder.

This is the code I have thus far...:

import os, sys
from os.path
import join
import re
import xlrd
from xlrd import open_workbook
import openpyxl
from openpyxl.reader.excel import load_workbook
import xlsxwriter


#All the paths
dict_folder = 'C:/Users//Documents//Test Excel' 
text_folder = 'C:/Users//Documents//Text'

words = set()
fieldset = set()
for file in os.listdir(dict_folder):
if file.endswith(".xlsx"):
wb1 = load_workbook(join(dict_folder, file), data_only = True)
ws = wb1.active
   #Here I am reading and printing all the data source names set(words) in the 
excel dictionaries:
cellvalues = ws["A1"].value
wordsextract = re.findall(r"\((.+?)\)", str(cellvalues))
results = wordsextract[0]
words.add(results)
print(results)

for rowofcellobj in ws["C" : "D"]:
for cellobj in rowofcellobj:
   #2. Here I am printing all the field names in col C & D in the excel 
dictionaries:
data = re.findall(r"\w+_.*?\w+", str(cellobj.value))
if data != []:
fields = data[0]
fieldset.add(fields)
print(fieldset)
#listing = str.remove("")
#print(listing)   


#Here I am reading the name of each .txt file to the separate .xlsx file:
for r, name in enumerate(os.listdir(text_folder)):
if name.endswith(".txt"):
print(name)

#Reading .txt file and trying to make the sentence into words instead of lines 
so that I can compare the individual .txt file words with the .xlsx file 
txtfilespath = os.chdir("C:/Users//Documents//Text")


#Here I am reading and printing all the words in the .txt files and compare 
with the excel Cell A1:
for name in os.listdir(txtfilespath):
if name.endswith(".txt"):
with open (name, "r") as texts:
# Read each line of the file:
s = texts.read()
print(s)


#if .txt files contain.() or select or from or words from 
sets..search that sentence and extract the common fields

result1 = []
parens = 0
buff = ""
for line in s:
if line == "(":
parens += 1
if parens > 0:
buff += line
if line == ")":
parens -= 1
   if not parens and buff:
result1.append(buff)
buff = ""
set(result1)

#Here, I include other keywords other than those found in the Excel workbooks 
   checkhere = set()   
   checkhere.add("Select")
   checkhere.add("From")
   checkhere.add("select")
   checkhere.add("from")
   checkhere.add("SELECT")
   checkhere.add("FROM")
   # k = list(checkhere)
   # print(k)  

   #I only want to read/ extract the lines containing brackets () as well as 
the keywords in the checkhere set. So that I can check capture the source and 
field in each line:
   #I tried this but nothing was printed..
   for element in checkhere:
   if element in result1:
print(result1)


My desired output for the code that could not be printed when I tried is:

(/* 1.select_no., bi FROM apple_x_Ex_x */ 
 proc sql; "TRUuuuth")

(/* 1.x FROM x*/ 
proc sql; "TRUuuuth")

(SELECT abc AS abc1, ab33_2_ AS mon, a_rr, iirir_vf, jk_ff, sfa_jfkj
FROM &orange..xxx_xxx_xxE
 where (asre(kkk_ix as format '-xx') gff &bcbcb_hhaha.) and 
  (axx(xx_ix as format '-xx') lec &jgjsd_vnv.)
 )

 (/* 1.select_no. FROM apple_x_Ex_x */ 
 proc sql; "TRUuuuth")

 (SELECT abc AS kf, mcfg_2_ AS dokn, b_rr, jjhj_vf, jjjk_hj, fjjh_jhjkj
FROM &bfbd..pear_xxx_xxE
 where (afdfe(kkffk_ix as format 'd-xx') gdaff &bcdadabcb_hdahaha.) and 
  (axx(xx_ix as format '-xx') lec &jgjsdfdf_vnv.)
 )



After which, if I'm able to get the desired output above, I will then compare 
these lines against the word set() and the fieldset set().

Any help would really be appreciated here..thank you
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: issue in handling CSV data

2019-09-08 Thread Peter J. Holzer
On 2019-09-08 05:41:07 -0700, Sharan Basappa wrote:
> On Sunday, 8 September 2019 04:56:29 UTC-4, Andrea D'Amore  wrote:
> > On Sun, 8 Sep 2019 at 02:19, Sharan Basappa  
> > wrote:
> > > As you can see, the string "\t"81 is causing the error.
> > > It seems to be due to char "\t".
> > 
> > It is not clear what format do you expect to be in the file.
> > You say "it is CSV" so your actual payload seems to be a pair of three
> > bytes (a tab and two hex digits in ASCII) per line.
> 
> The issue seems to be presence of tabs along with the numbers in a single 
> string. So, when I try to convert strings to numbers, it fails due to 
> presence of tabs.
> 
> Here is the hex dump:
> 
> 22 61 64 64 72 65 73 73 2c 22 09 22 6c 65 6e 67 
> 74 68 2c 22 09 22 38 31 2c 22 09 35 63 0d 0a 22 
> 61 64 64 72 65 73 73 2c 22 09 22 6c 65 6e 67 74 
...

This looks like this:

"address,"  "length,"   "81,"   5c
"address,"  "length,"   "04,"   11
"address,"  "length,"   "e1,"   17
"address,"  "length,"   "6a,"   6c
...

Note that the commas are within the quotes. I'd say Andrea is correct:
This is a tab-separated file, not a comma-separated file. But for some
reason all fields except the last end with a comma. 

I would 

a) try to convince the person producing the file to clean up the mess

b) if that is not successful, use the csv module to read the file with
   separator tab and then discard the trailing commas.

hp


-- 
   _  | Peter J. Holzer| we build much bigger, better disasters now
|_|_) || because we have much more sophisticated
| |   | h...@hjp.at | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson 


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Python-ideas] Re: Automatic translation of Python to assembly language

2019-09-08 Thread Chris Angelico
On Mon, Sep 9, 2019 at 4:12 AM Mark @pysoniq  wrote:
>
> "I don't think the ctypes wrapper in itself is very interesting."
>
> Well, we disagree on that!  I think that automatic generation of a ctypes 
> wrapper to connect Python to assembly is interesting and a huge timesaver.
>
> "I don't know where to find those blog entries."
>
> The blogs can be reached directly at:  https://pysoniq.com/text_16.htm and 
> there is a link "Blog" on the home page.  That link should light up when you 
> go to the link I've just provided.
>
> If you read the 3rd & 4th entries -- Assembly Optimizations in Complex 
> Calculations — Part 1 of 2 and Assembly Optimizations in Complex Calculations 
> — Part 2 of 2, those blog posts contain a step-by-step breakdown of 
> translating Python source to assembly language.  And the NASM source is 
> linked there and is also available at the Resources link, so you can follow 
> along between the Python source and the assembly listing.
>
> Your questions are helpful!
>

Redirecting this to python-list as this is not discussing any actual
Python language or interpreter ideas. Please remove python-ideas from
cc for future replies.

Your blog breaks the browser's Back button. Please don't do that; if
you want people to read your content, make it easy for us to do so.

How does your assembly translation cope with the possibility that
"round(h, 2)" might not call the Python standard library round()
function? You go to great lengths to show how you can optimize a
specific type of calculation that appears to be specifically relating
to floating-point math, including a number of steps that are basically
the same as a peephole optimizer could do - or, for that matter, any
programmer could easily do manually (I don't see a lot of loops in the
real world that go "for a in n" and then "v0 = a" with no other use of
a). What would happen if integers were involved? Remember, Python's
integers can happily grow beyond any CPU register - will your
transformation maintain the semantics of Python, or will it assume
that everything is floating-point?

> This line is self-explanatory.  It takes the input array "n" and loops 
> through each data point.  The input array "n" is 64-bit double-precision 
> floating point.

How do you ensure that this is an array of 64-bit floating-point values?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: local variable 'p' referenced before assignment

2019-09-08 Thread Pankaj Jangid
David  writes:
>
https://docs.python.org/3/faq/programming.html#what-are-the-rules-for-local-and-global-variables-in-python
 
>
> " If a variable is assigned a value anywhere within the function’s body,
> it’s assumed to be a local unless explicitly declared as global."
>

Coming with a baggage of other languages. :-) I should have searched
it. Thanks a lot for sharing this.

Regards.

-- 
Pankaj Jangid
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Python-ideas] Re: Automatic translation of Python to assembly language

2019-09-08 Thread Skip Montanaro
ChrisA> Your blog breaks the browser's Back button. Please don't do that; if
ChrisA> you want people to read your content, make it easy for us to do so.

Mark,

I didn't even go that far. If you want me to read your blog, please
load the individual essays into separate pages, not a narrow scrolling
window. Heck, most/all links should just open a new page. Why the
narrow scrolling widget?

Further, as far as I can tell, you don't provide any details about how
well it conforms to existing CPython semantics. For example:

* What version(s) of Python are you targeting?

* Does the entire test suite pass? If not, what fails?

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Finding lines in .txt file that contain keywords from two different set()

2019-09-08 Thread MRAB

On 2019-09-08 17:02, A S wrote:

My problem is seemingly profound but I hope to make it sound as simplified as 
possible.Let me unpack the details..:

1. I have one folder of Excel (.xlsx) files that serve as a data dictionary.

-In Cell A1, the data source name is written in between brackets

-In Cols C:D, it contains the data field names (It could be in either col C or 
D in my actual Excel sheet. So I had to search both columns

-*Important: I need to know which data source the field names come from

2. I have another folder of Text (.txt) files that I need to parse through to 
find these keywords.

These are the folders used for a better reference ( 
https://drive.google.com/open?id=1_LcceqcDhHnWW3Nrnwf5RkXPcnDfesq ). The files 
are found in the folder.

This is the code I have thus far...:


[snip]
result1 contains a list of strings. None of the words in 'checkhere' are 
in that list. I think what you intended to do was to check whether any 
of those words are in any of the strings of result1:


for element in checkhere:
for r in result1:
if element in r:
print(r)
# Found one, so stop looking for more.
break
--
https://mail.python.org/mailman/listinfo/python-list


Re: Finding lines in .txt file that contain keywords from two different set()

2019-09-08 Thread DL Neil via Python-list

On 9/09/19 4:02 AM, A S wrote:

My problem is seemingly profound but I hope to make it sound as simplified as 
possible.Let me unpack the details..:


...


These are the folders used for a better reference ( 
https://drive.google.com/open?id=1_LcceqcDhHnWW3Nrnwf5RkXPcnDfesq ). The files 
are found in the folder.



The link resulted in a 404 page (for me - but then I don't use Google). 
So, without any sample data...


> 1. I have one folder of Excel (.xlsx) files that serve as a data 
dictionary.

>
> -In Cell A1, the data source name is written in between brackets
>
> -In Cols C:D, it contains the data field names (It could be in either 
col C or D in my actual Excel sheet. So I had to search both columns

>
> -*Important: I need to know which data source the field names come from
>
> 2. I have another folder of Text (.txt) files that I need to parse 
through to find these keywords.



Recommend you start with a set of test data/directories. For the first 
run, have one of each type of file, where the keywords correlate. Thus 
prove that the system works when you know it should.


Next, try the opposite, to ensure that it equally-happily ignores, when 
it should.


Then expand to having multiple records, so that you can see what happens 
when some files correlate, and some don't.


ie take a large problem and break it down into smaller units. This is a 
"top-down" method.



An alternate design approach (which works very well in Python - see also 
"PyTest") is to embrace the principles of TDD (Test-Driven Development). 
This is a process that builds 'from the ground, up'. In this, we design 
a small part of the process - let's call it a function/method: first we 
code some test data *and* the expected answer, eg if one input is 1 and 
another is 2 is their addition 3? (running such a test at this stage 
will fail - badly!); and then we write some code - and keep perfecting 
it until it passes the test.


Repeat, stage-by-stage, to build the complete program - meantime, every 
change you make to the code should be tested against not just 'its own' 
test, but all of the tests which originally related to some other 
smaller unit of the whole. In this way, 'new code' can be shown to break 
(or not - hopefully) previously implemented, tested, and 'proven' code!


Notice how you have broken-down the larger problem in the description 
(points 1 to 5, above)! Design the tests similarly, to *only* test one 
small piece of the puzzle (often you will have to 'fake' or "mock" 
data-inputs to the process, particularly if code to produce that unit's 
input has yet to be written, but regardless 'mock data' is thoroughly 
controlled and thus produces (more) predictable results) - plus, it's 
much easier to spot errors and omissions when you don't have to wade 
through a mass of print-outs that (attempt to) cover *everything*! (IMHO)


Plus, when a problem is well-confined, there's less example code and 
data to insert into list questions, and the responses will be 
equally-focussed!



Referring back to the question: it seems that the issue is either that 
the keywords are not being (correctly) picked-out of the sets of files 
(easy tests - for *only* those small section of the code!), or that the 
logic linking the key-words is faulty (another *small* test, easily 
coded - and at first fed with 'fake' key-words which prove the various 
test cases, and thus, when run, (attempt to) prove your logic and code!)



--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Color representation as rgb, int and hex

2019-09-08 Thread Eko palypse
I'm confused about the following

import sys
print(tuple(bytes.fromhex('282C34')))
print(tuple((0x282C34).to_bytes(3, byteorder=sys.byteorder)))

which results in 

(40, 44, 52)
(52, 44, 40)

on my machine. Shouldn't I expect the same result?

Thank you
Eren
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Color representation as rgb, int and hex

2019-09-08 Thread MRAB

On 2019-09-08 20:58, Eko palypse wrote:

I'm confused about the following

import sys
print(tuple(bytes.fromhex('282C34')))
print(tuple((0x282C34).to_bytes(3, byteorder=sys.byteorder)))

which results in

(40, 44, 52)
(52, 44, 40)

on my machine. Shouldn't I expect the same result?


You haven't said whether your machine is big-endian or little-endian.

On a little-endian machine a 4-byte integer 0x282C34 is stored as:

34 2C 28 00
-> increasing address ->

On a big-endian machine a 4-byte integer 0x282C34 is stored as:

00 28 2C 34
-> increasing address ->
--
https://mail.python.org/mailman/listinfo/python-list


Re: [Python-ideas] Re: Automatic translation of Python to assembly language

2019-09-08 Thread Roel Schroeven

Skip Montanaro schreef op 8/09/2019 om 21:17:

ChrisA> Your blog breaks the browser's Back button. Please don't do that; if
ChrisA> you want people to read your content, make it easy for us to do so.

Mark,

I didn't even go that far. If you want me to read your blog, please
load the individual essays into separate pages, not a narrow scrolling
window. Heck, most/all links should just open a new page. Why the
narrow scrolling widget?


It seems to be a badly tuned responsive design. If I use Firefox's 
zoom-in, things get a bit better and more readable.


--
"Honest criticism is hard to take, particularly from a relative, a
friend, an acquaintance, or a stranger."
-- Franklin P. Jones

Roel Schroeven

--
https://mail.python.org/mailman/listinfo/python-list


Re: Color representation as rgb, int and hex

2019-09-08 Thread Chris Angelico
On Mon, Sep 9, 2019 at 6:01 AM Eko palypse  wrote:
>
> I'm confused about the following
>
> import sys
> print(tuple(bytes.fromhex('282C34')))
> print(tuple((0x282C34).to_bytes(3, byteorder=sys.byteorder)))
>
> which results in
>
> (40, 44, 52)
> (52, 44, 40)
>
> on my machine. Shouldn't I expect the same result?

Your first example is a sequence of three bytes: 28 in the first
position, then 2C, then 34 in the last position.

Your second example has 28 in the most-significant byte, 2C in the
middle, and 34 in the least-significant byte.

For those to come out identical, the concepts of "most-significant
byte" and "first position" have to mean the same, which means you want
big-endian, which is also referred to as "network byte order". So
don't use sys.byteorder - just explicitly ask for big-endianness:

print(tuple((0x282C34).to_bytes(3, "big")))
(40, 44, 52)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Color representation as rgb, int and hex

2019-09-08 Thread Eko palypse
> You haven't said whether your machine is big-endian or little-endian.

Correct, it is little but I'm wondering why this isn't taking into account.
I thought a method called fromhex would imply that bytes for an integer
should be created and as that it would use the proper byte order to create it.
But it seems that it treats the string literally.
Isn't that confusing?

Eren
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Color representation as rgb, int and hex

2019-09-08 Thread Eko palypse
> ChrisA

You are correct, but, sorry for not being clear what confused me.
I assumed it would use the sys.byteorder but I guess this is simply a
AssumedError exception.  :-)


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Color representation as rgb, int and hex

2019-09-08 Thread Chris Angelico
On Mon, Sep 9, 2019 at 6:37 AM Eko palypse  wrote:
>
> > You haven't said whether your machine is big-endian or little-endian.
>
> Correct, it is little but I'm wondering why this isn't taking into account.
> I thought a method called fromhex would imply that bytes for an integer
> should be created and as that it would use the proper byte order to create it.
> But it seems that it treats the string literally.
> Isn't that confusing?
>

No, constructing a bytes literal from hex digits implies that they
follow the sequence in the string of digits. It's nothing to do with
the endinanness of integers.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is it 'fine' to instantiate a widget without parent parameter?

2019-09-08 Thread jfong
David於 2019年9月8日星期日 UTC+8下午8時14分03秒寫道:
> On Sun, 8 Sep 2019 at 21:05,  wrote:
> > David於 2019年9月8日星期日 UTC+8下午6時44分55秒寫道:
> > > On Sun, 8 Sep 2019 at 20:25,  wrote:
> 
> > > > If I have two widgets created this way:
> > > > t0 = tkinter.Text()
> > > > t1 = tkinter.Text()
> > > > How many Tk objects will there be?
> 
> > Sorry, didn't make it clear. I mean 
> 
> Sorry I didn't read more carefully.
> But I think that the method I demonstrated can give
> the answer to your question.
> 
> >>> import tkinter
> >>> t0 = tkinter.Text()
> >>> t1 = tkinter.Text()
> >>> t0.master
> 
> >>> t1.master
> 
> >>> t0.master is t1.master
> True
> >>>

Thank you. After a quick trace to find out the reason, I found that Tkinter 
prevents Tk() be called more than once from widget constructors, so only one Tk 
object exists:-)

--Jach
-- 
https://mail.python.org/mailman/listinfo/python-list