Re: Checking refusal of a network connection

2019-06-01 Thread Markus Elfring
> Also, it can be very useful to strace the client process, eg:

Do you find the following background information more helpful
for the desired clarification of unexpected software behaviour?

elfring@Sonne:~/Projekte/Python> LANG=C strace -e trace=network 
/usr/bin/python3 socket-send_json_data.py --server_id localhost --server_port 
37351
Using Python version:
3.7.2 …
socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 3
socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0) = 5
socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 4
connect(4, {sa_family=AF_UNIX, sun_path="/var/run/nscd/socket"}, 110) = 0
sendto(4, "\2\0\0\0\r\0\0\0\6\0\0\0hosts\0", 18, MSG_NOSIGNAL, NULL, 0) = 18
recvmsg(4, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="hosts\0", 
iov_len=6}, {iov_base="\310O\3\0\0\0\0\0", iov_len=8}], msg_iovlen=2, 
msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, 
cmsg_data=[5]}], msg_controllen=20, msg_flags=MSG_CMSG_CLOEXEC}, 
MSG_CMSG_CLOEXEC) = 14
connect(3, {sa_family=AF_INET, sin_port=htons(37351), 
sin_addr=inet_addr("127.0.0.1")}, 16) = -1 ECONNREFUSED (Connection refused)
Traceback …:
…
  File "socket-send_json_data.py", line 17, in send_data
so.connect((args.server_id, args.server_port))
ConnectionRefusedError: [Errno 111] Connection refused
+++ exited with 1 +++


> You can also strace the running service process:

I do not observe additional function calls for the TCP client connection
attempt here.


> Also, on the service side it isn't enough to create the service socket,
> you also need to do an accept IIRC.

This should be performed by my implementation of the C++ function “setup”.

Regards,
Markus
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Checking refusal of a network connection

2019-06-01 Thread Markus Elfring
>> connect(3, {sa_family=AF_INET, sin_port=htons(37351), 
>> sin_addr=inet_addr("127.0.0.1")}, 16) = -1 ECONNREFUSED (Connection refused)
>
>   Without seeing the code, I'd be suspicious of that difference.

I would expect that the IPv4 address from such a connection attempt
would be automatically converted to a IPv6 loopback address.

Unfortunately, the direct specification “… socket-send_json_data.py --server_id 
::1 …”
does not work at the moment because of the error message “socket.gaierror: 
[Errno -9]
Address family for hostname not supported”.

Regards,
Markus
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Checking refusal of a network connection

2019-06-01 Thread Peter J. Holzer
On 2019-06-01 19:15:28 +0200, Markus Elfring wrote:
> >> connect(3, {sa_family=AF_INET, sin_port=htons(37351), 
> >> sin_addr=inet_addr("127.0.0.1")}, 16) = -1 ECONNREFUSED (Connection 
> >> refused)
> > Without seeing the code, I'd be suspicious of that difference.
> 
> I would expect that the IPv4 address from such a connection attempt
> would be automatically converted to a IPv6 loopback address.

You haven't said which OS you are using, but as far as I know this
expectation will be frustrated at least on Linux: There ::1 and
127.0.0.1 are distinct addresses. If you want to accept connections on
both, you have to listen on both (or on ::, which does accept
connections on all IP addresees - IPv6 and IPv4).

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: Checking refusal of a network connection

2019-06-01 Thread Michael Torrie
On 06/01/2019 11:15 AM, Markus Elfring wrote:
>>> connect(3, {sa_family=AF_INET, sin_port=htons(37351), 
>>> sin_addr=inet_addr("127.0.0.1")}, 16) = -1 ECONNREFUSED (Connection refused)
>>
>>  Without seeing the code, I'd be suspicious of that difference.
> 
> I would expect that the IPv4 address from such a connection attempt
> would be automatically converted to a IPv6 loopback address.

How would this conversion take place?  Localhost is 127.0.0.1.
Localhost6 is ::1.  They are different and you cannot route between the two.

What I can see is that your server binds to localhost6 and your client
is trying to connect to localhost.

> Unfortunately, the direct specification “… socket-send_json_data.py 
> --server_id ::1 …”
> does not work at the moment because of the error message “socket.gaierror: 
> [Errno -9]
> Address family for hostname not supported”.

No idea on that one.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PEP 594 cgi & cgitb removal

2019-06-01 Thread Peter J. Holzer
On 2019-05-25 23:45:06 +0200, Roel Schroeven wrote:
> Jon Ribbens via Python-list schreef op 25/05/2019 om 21:00:
> > On 2019-05-25, Michael Torrie  wrote:
> > > On 05/24/2019 04:27 AM, Jon Ribbens via Python-list wrote:
> > > > Sorry, in what sense do you mean "Serverless is CGI"?
> > > > 
> > > > As far as I can tell, it's just a script to automatically upload
> > > > bits of code into various cloud providers, none of which use CGI.
> > > 
> > > Not really.  Serverless just means stateless web-based remote procedure
> > > calls.  This is by definition what CGI is.
> > 
> > No, it isn't. CGI is a specific API and method of calling a program
> > in order to serve a web request. It isn't a shorthand for "any
> > web-based remote procedure call".
> 
> More specifically, with CGI the webserver starts a new process for every
> single request. That's bad enough for a light C program, but it's certainly
> not a good idea to start a whole new Python process for every request. At
> least not for any production website or web service that serves any real
> amount of traffic.

I strongly disagree with this. A minimal Python script using the cgi
package takes between 50 and 80 milliseconds on my (not very fast)
private server. Assuming a script which does anything useful takes about
100 milliseconds, that's still 

a) a shorter response time than a lot of websites with persistent
servers have
b) fast enough not be a bottleneck on the vast majority of web sites.
Yes, you cannot run Facebook on CGI, but most websites aren't
Facebook. I doubt we have even one website which gets close to 10 
requests to dynamic content per second. Much less 10 requests per
second per core.

I don't use CGI very much these days (and when I do, I use Perl - old
habits die hard), but performance isn't the reason.

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: Handling an connection error with Twython

2019-06-01 Thread Peter J. Holzer
On 2019-05-25 13:46:40 +0200, Cecil Westerhof wrote:
> Just changing the while loop to a for loop did not make sense to me,
> but this does. I now have:
> max_tries = 5
> for current_try in range(1, max_tries):
> try:
> posted = twitter.update_status(status = message,
>in_reply_to_status_id = message_id,
>trim_user = True)
> return posted['id']
> except TwythonError as e:
> if not 'Temporary failure in name resolution' in e.msg:
> raise
> timed_message('Failed on try: {0} of {1}'.format(current_try, 
> max_tries))
> if current_try == max_tries:
 
 This will never be true because the loop will exit
 before current_try reaches max_tries.
> print('Could not get a connection to the internet: exiting')
> deinit(2)
Also you don't seem to stop here (unless deinit raises
an exception)

> time.sleep(60)
> raise RuntimeError('Should not get here')
 ^
  So if you can't get a status update you will reach this point.

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: Checking refusal of a network connection

2019-06-01 Thread Markus Elfring
>> I would expect that the IPv4 address from such a connection attempt
>> would be automatically converted to a IPv6 loopback address.
>
> You haven't said which OS you are using, but as far as I know this
> expectation will be frustrated at least on Linux: There ::1 and
> 127.0.0.1 are distinct addresses.

How does this view fit to information from the Linux programmer's manual?
See also: command “man 7 ipv6”

Regards,
Markus
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Checking refusal of a network connection

2019-06-01 Thread Peter J. Holzer
On 2019-06-01 20:22:39 +0200, Markus Elfring wrote:
> >> I would expect that the IPv4 address from such a connection attempt
> >> would be automatically converted to a IPv6 loopback address.
> >
> > You haven't said which OS you are using, but as far as I know this
> > expectation will be frustrated at least on Linux: There ::1 and
> > 127.0.0.1 are distinct addresses.
> 
> How does this view fit to information from the Linux programmer's manual?
> See also: command “man 7 ipv6”

Which specific information in that man page contradicts what what I
wrote?

If you think of 

| IPv4 connections can be handled with the v6 API by using the
| v4-mapped-on-v6 address type; thus a program needs to support only
| this API  type to  support  both  protocols.

please note that 127.0.0.1 mapped to IPv6 is ::7f00:1, not ::1. So you
still need to bind to two addresses.

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: Checking refusal of a network connection

2019-06-01 Thread Markus Elfring
> Which specific information in that man page contradicts what I wrote?

We can agree that the mentioned IP addresses are distinct.
But the corresponding functionality should be equivalent.


> If you think of
>
> | IPv4 connections can be handled with the v6 API by using the
> | v4-mapped-on-v6 address type; thus a program needs to support only
> | this API  type to  support  both  protocols.
>
> please note that 127.0.0.1 mapped to IPv6 is ::7f00:1, not ::1.

I find another information like “This is handled transparently by
the address handling functions in the C library.” also interesting.


> So you still need to bind to two addresses.

I am unsure about this conclusion.

Under which circumstances will the Python programming interfaces
support the direct usage of the identification “::1”?

Regards,
Markus
-- 
https://mail.python.org/mailman/listinfo/python-list


Getter is not returning the data it should be

2019-06-01 Thread Barb Cr33k
I have a parent Class that has a setter that returns queryFiltre value and a 
getter that is supposed to pass the queryFiltre value to my child Class. 
queryFiltre Should return an SQL query like "SELECT * FROM Report WHERE GA_RPM 
> 0 and CAMPAIGN LIKE '%TT%'... ".

The print() in the setter returns a SQL query, but the print() of the getter 
when called in the child Class returns something like " ".

What's wrong with my code? Please bear with me as I'm still learning and oop is 
still an abstract concept in my head.

I've added comments in the code so you can see what happens where:



class SimpleGrid(gridlib.Grid): ##, mixins.GridAutoEditMixin):
def __init__(self, parent, log):
gridlib.Grid.__init__(self, parent, -1)


### DATABASE CONNECT 
self.path =os.path.dirname(os.path.realpath(__file__))
self.dbfile = os.path.join(self.path , "report.db")
self.db_conn = sqlite3.connect(self.dbfile)
self.theCursor =  self.db_conn.cursor()
### SETTING FILE CONNECT 
self.configFile = os.path.join(self.path , "config.ini")
self.config = configparser.ConfigParser()
self.config.read(self.configFile)

### Calling th Getter and Setter
self.queryFiltre = self.setQueryFiltre(self)
self.getQueryFiltre()

### Setter
def setQueryFiltre(self,queryFiltre):

if self.config.get('Network', 'taboola') == "true" and 
self.config.get('Network', 'ob') == "true":
network = ""
elif self.config.get('Network', 'taboola') == "true" and 
self.config.get('Network', 'ob') == "false":
network = " and CAMPAIGN LIKE '%TB%'"
elif self.config.get('Network', 'outbrain') == "true" and 
self.config.get('Network', 'tb') == "false":
network = " and CAMPAIGN LIKE '%OB%'"
else:
network = ""

queryFiltre = "SELECT * FROM Report WHERE  GA_RPM > 0 " + network + 
"  and STATUS = '1' ORDER BY CLICKS DESC"

### The print below returns the right value of queryFiltre
print(queryFiltre)

return queryFiltre

### Getter
def getQueryFiltre(queryFiltre):
queryFiltre = queryFiltre
return queryFiltre


class TestFrame(wx.Frame):
def __init__(self, parent, log):
wx.Frame.__init__(self, parent, 0, "Native Ads Reports V1.0", 
size=(1400,800))
self.grid = SimpleGrid(self, log)

### Calling the Getter of the parent Class
self.queryFiltre = self.grid.getQueryFiltre()

### DATABASE CONNECT
self.path =os.path.dirname(os.path.realpath(__file__))
self.dbfile = os.path.join(self.path , "report.db")
self.db_conn = sqlite3.connect(self.dbfile)
self.theCursor =  self.db_conn.cursor()

### The print below returns a bad value, something like : 
<__main__.SimpleGrid object at 0x042AF2B0>
print(self.queryFiltre)


You'll notice also that I've added the script to define the path and to connect 
to the db in both classes, is there a way to do it only once in the first Class?

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


Re: Handling an connection error with Twython

2019-06-01 Thread Cecil Westerhof
"Peter J. Holzer"  writes:

> On 2019-05-25 13:46:40 +0200, Cecil Westerhof wrote:
>> Just changing the while loop to a for loop did not make sense to me,
>> but this does. I now have:
>> max_tries = 5
>> for current_try in range(1, max_tries):
>> try:
>> posted = twitter.update_status(status = message,
>>in_reply_to_status_id = 
>> message_id,
>>trim_user = True)
>> return posted['id']
>> except TwythonError as e:
>> if not 'Temporary failure in name resolution' in e.msg:
>> raise
>> timed_message('Failed on try: {0} of {1}'.format(current_try, 
>> max_tries))
>> if current_try == max_tries:
>  
>  This will never be true because the loop will exit
>  before current_try reaches max_tries.
>> print('Could not get a connection to the internet: exiting')
>> deinit(2)
> Also you don't seem to stop here (unless deinit raises
> an exception)
>
>> time.sleep(60)
>> raise RuntimeError('Should not get here')
>  ^
>   So if you can't get a status update you will reach this point.

Oops, you are completely right. :'-( The for should be:
for current_try in range(1, max_tries + 1):

A bit silly of me.


The function deinit does some deinitialisation and after that an exit
with the value it receives. (Default it uses 0.) So you never return
from this call. Should have made that clear.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Checking refusal of a network connection

2019-06-01 Thread Markus Elfring
> It looks like the service isn't listening at the time the so.connect is 
> called.

* I get an other impression from the programs “/usr/bin/netstat” and 
“/usr/bin/ss”.

* The data transmission seems to work also for my small script 
“socket-send_test_data1.tcl”
  (even when the identification “::1” was passed as a command parameter).

Regards,
Markus
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Getter is not returning the data it should be

2019-06-01 Thread DL Neil

Bonjour Barb,

Please allow me to answer your question, somewhat, backwards:-

There is a principle in program design known as "separation of 
concerns". If you look at the class SimpleGrid and consider that the 
bulk of its code lies after the first comment, how would you summarise 
(in English) its actions? Does the answer contain the word "database" 
more often than any word relating to wxPython?


- Might it simplify matters if the functions related to those two words 
were separated?


Thus, let's look at the overall objective in the manner of OOP. There is 
a data-source (or two) and an output screen/frame/grid. Let's go 
completely 'purist' and create an object for each one.


- As soon as the 'database' (or query) object is created, does it answer 
the "both classes" question, below?


What is the need for separate (database) "getter" and "setter" methods? 
Once the query text has been built, why not query the DB immediately?


Please review "getQueryFiltre". Again, summarise (in English) exactly 
what you think/want this method to do.


- If the two separate methods are required, and they both appear in a 
'database' object, then make the query an attribute of that object 
(self) and you won't need to pass the query as a result/parameter.


- However, in Python we don't need to do that anyway because if 
setQueryFiltre set self.queryFiltre (instead of returning it) the 
calling-code would be able to access db.queryFiltre without any need for 
a "getter" (this Python idiom is quite different to many other 
programming languages, eg Java!)


Once the DB and screen operations have been separated:

(a) you will be able to test the DB code-operations independently and 
ensure the correct data is being retrieved for each usual- and 
special-case; and
(b) you will no longer receive the quite mystifying SimpleGrid errmsg 
(from wxPython) when you are expecting something data-related to be 
returned!



On 2/06/19 6:52 AM, Barb Cr33k wrote:

I have a parent Class that has a setter that returns queryFiltre value and a getter that is 
supposed to pass the queryFiltre value to my child Class. queryFiltre Should return an SQL 
query like "SELECT * FROM Report WHERE GA_RPM > 0 and CAMPAIGN LIKE '%TT%'... ".

The print() in the setter returns a SQL query, but the print() of the getter when called in the 
child Class returns something like " ".

What's wrong with my code? Please bear with me as I'm still learning and oop is 
still an abstract concept in my head.

I've added comments in the code so you can see what happens where:



class SimpleGrid(gridlib.Grid): ##, mixins.GridAutoEditMixin):
 def __init__(self, parent, log):
 gridlib.Grid.__init__(self, parent, -1)


 ### DATABASE CONNECT
 self.path =os.path.dirname(os.path.realpath(__file__))
 self.dbfile = os.path.join(self.path , "report.db")
 self.db_conn = sqlite3.connect(self.dbfile)
 self.theCursor =  self.db_conn.cursor()
 ### SETTING FILE CONNECT
 self.configFile = os.path.join(self.path , "config.ini")
 self.config = configparser.ConfigParser()
 self.config.read(self.configFile)

 ### Calling th Getter and Setter
 self.queryFiltre = self.setQueryFiltre(self)
 self.getQueryFiltre()

 ### Setter
 def setQueryFiltre(self,queryFiltre):

 if self.config.get('Network', 'taboola') == "true" and 
self.config.get('Network', 'ob') == "true":
 network = ""
 elif self.config.get('Network', 'taboola') == "true" and 
self.config.get('Network', 'ob') == "false":
 network = " and CAMPAIGN LIKE '%TB%'"
 elif self.config.get('Network', 'outbrain') == "true" and 
self.config.get('Network', 'tb') == "false":
 network = " and CAMPAIGN LIKE '%OB%'"
 else:
 network = ""

 queryFiltre = "SELECT * FROM Report WHERE  GA_RPM > 0 " + network + "  
and STATUS = '1' ORDER BY CLICKS DESC"

 ### The print below returns the right value of queryFiltre
 print(queryFiltre)

 return queryFiltre

 ### Getter
 def getQueryFiltre(queryFiltre):
 queryFiltre = queryFiltre
 return queryFiltre


class TestFrame(wx.Frame):
 def __init__(self, parent, log):
 wx.Frame.__init__(self, parent, 0, "Native Ads Reports V1.0", 
size=(1400,800))
 self.grid = SimpleGrid(self, log)

 ### Calling the Getter of the parent Class
 self.queryFiltre = self.grid.getQueryFiltre()

 ### DATABASE CONNECT
 self.path =os.path.dirname(os.path.realpath(__file__))
 self.dbfile = os.path.join(self.path , "report.db")
 self.db_conn = sqlite3.connect(self.dbfile)
 self.theCursor =  self.db_conn.cursor()

 ### The print below returns a bad value, something like 

Socket.py SSM support

2019-06-01 Thread Max Franke
Hi,

as of right now there appears to be a lack of setsockoptions required to enable 
SSM, MCAST_JOIN_SOURCE_GROUP or something a kin to that in particular. Is there 
currently any effort to add those options or any other workaround to make SSM 
work in python natively? 

Best regards
Max
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Checking refusal of a network connection

2019-06-01 Thread Peter J. Holzer
On 2019-06-01 20:44:29 +0200, Markus Elfring wrote:
> > Which specific information in that man page contradicts what I wrote?
> 
> We can agree that the mentioned IP addresses are distinct.
> But the corresponding functionality should be equivalent.
> 
> 
> > If you think of
> >
> > | IPv4 connections can be handled with the v6 API by using the
> > | v4-mapped-on-v6 address type; thus a program needs to support only
> > | this API  type to  support  both  protocols.
> >
> > please note that 127.0.0.1 mapped to IPv6 is ::7f00:1, not ::1.

Oops, that should have been :::7f00:1.


> I find another information like “This is handled transparently by
> the address handling functions in the C library.” also interesting.

"Handled transparently" means that an ipv6 server can handle connections
from ipv4 clients without doing anything special. They just appear to
come from a specific IPv6 address range. It doesn't mean the OS performs
random address translations according to user's expectations of
"equivalence".


> > So you still need to bind to two addresses.
> 
> I am unsure about this conclusion.

Well, we don't study theology here. We don't have to theorize (no pun
intended), we can experiment. Why don't you just try it out?


> Under which circumstances will the Python programming interfaces
> support the direct usage of the identification “::1”?

I'm not sure I understand the question. They do.

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: Checking refusal of a network connection

2019-06-01 Thread Cameron Simpson

On 01Jun2019 12:57, Dennis Lee Bieber  wrote:

On Sat, 1 Jun 2019 15:33:43 +0200, Markus Elfring 
declaimed the following:

I don't know "strace" (I'd likely be running WireShark to capture all
traffic for investigation).


Sure, but that means you need to winnow it from any other traffic. The 
advantage of strace is that it watches the programme itself, and shows 
(in this case) the network system calls. It is great for seeing what the 
programme is doing/trying to do at the basic level. And, like wireshark, 
language independent - all runtimes have to go through the OS to get 
stuff done.  I've debugged third party java apps this way because the 
issue was a basic one like this.



connect(4, {sa_family=AF_UNIX, sun_path="/var/run/nscd/socket"}, 110) = 0



connect(3, {sa_family=AF_INET, sin_port=htons(37351), 
sin_addr=inet_addr("127.0.0.1")}, 16) = -1 ECONNREFUSED (Connection refused)


Without seeing the code, I'd be suspicious of that difference. The
latter is asking for a TCP/UDP family connection, whereas the first is a
UNIX domain socket. To my knowledge they are not compatible types.


They're certainly distinct address spaces. In other regards they're 
pretty compatible - you listen/connect the same way. A UNIX socket is 
just IPC within the kernel instead of over the network.


However, the former connect is to the OS name service (hostname lookup - 
it will mediate to the /etc/hosts file, DNS, NIS or whatever other name 
services may be set up). The latter is his connection attempt to his 
service.


So this difference is expected and on the surface it looks correct.

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to concatenate strings with iteration in a loop?

2019-06-01 Thread DL Neil

On 21/05/19 8:40 PM, Paul Moore wrote:

On Tue, 21 May 2019 at 09:25, Frank Millman  wrote:


On 2019-05-21 9:42 AM, Madhavan Bomidi wrote:

Hi,

I need to create an array as below:

tempStr = year+','+mon+','+day+','+str("{:6.4f}".format(UTCHrs[k]))+','+ \
str("{:9.7f}".format(AExt[k,0]))+','+str({:9.7f}".format(AExt[k,1]))+','+ \
str("{:9.7f}".format(AExt[k,2]))+','+str("{:9.7f}".format(AExt[k,3]))+','+ \
str("{:9.7f}".format(AExt[k,4]))+','+str("{:9.7f}".format(AExt[k,5]))+','+ \
str("{:9.7f}".format(AExt[k,6]))+','+str("{:9.7f}".format(AExt[k,7]))+','+ \
str("{:9.7f}".format(AExt[k,8]))+','+str("{:9.7f}".format(AExt[k,9]))


k is a row index

Can some one suggest me how I can iterate the column index along with row index 
to concatenate the string as per the above format?

Thanks in advance



The following (untested) assumes that you are using a reasonably
up-to-date Python that has the 'f' format operator.

tempStr = f'{year},{mon},{day},{UTCHrs[k]:6.4f}'
for col in range(10):
  tempStr += f',{AExt[k, col]:9.7f}'



As a minor performance note (not really important with only 10 items,
but better to get into good habits from the start):

temp = [f'{year},{mon},{day},{UTCHrs[k]:6.4f}']
for col in range(10):
  temp.append(f',{AExt[k, col]:9.7f}')

tempStr = ''.join(tempStr)

Repeated concatenation of immutable strings (which is what Python has)
is O(N**2) in the number of chunks added because of the need to
repeatedly copy the string.



A more pythonic approach might be to eschew the "k is a row index" and 
resultant range(), by gathering the temperature readings into a 
list/tuple (tuple unpacking at read-step or zip(), as appropriate). The 
point of which (hah!) is to get rid of "pointers", and replace the 
'algebra' with more readable code.


The collection can then be processed into the string using .append() 
and/or .join(), perhaps with a list comprehension/generator...



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


tkinter.tix "Control" widget don't work with StringVar?

2019-06-01 Thread jfong
Below is a simplified version of the sample script downloaded from its package.
When run it, the entry field display '0' instead of 'P&W'.
PS. I am using Python 3.4.4, Windows 32bit

test0.py
 1 from tkinter import tix as Tix
 2 
 3 root = Tix.Tk()
 4 
 5 demo_maker = Tix.StringVar()
 6 demo_maker.set('P&W')
 7 
 8 c = Tix.Control(root, label='Engine Maker: ',
 9variable=demo_maker,
10options='entry.width 10 label.width 20 label.anchor e')
11 c.pack(side=Tix.TOP, anchor=Tix.W)
12 
13 root.mainloop()


I run it under pdb, try to figure out where the problem is:

D:\Works\Python>py -m pdb test0.py
> d:\works\python\test0.py(1)()
-> from tkinter import tix as Tix
(Pdb) tbreak 13
Breakpoint 1 at d:\works\python\test0.py:13
(Pdb) cont
Deleted breakpoint 1 at d:\works\python\test0.py:13
> d:\works\python\test0.py(13)()
-> root.mainloop()
(Pdb) !c['value']
'0'
(Pdb) !demo_maker.get()
'P&W'
(Pdb) quit

If I change line 8 to "c = Tix.Control(root, label='Engine Maker: ', 
value='P&W',", the result is very interest:

D:\Works\Python>py -m pdb test0.py
> d:\works\python\test0.py(1)()
-> from tkinter import tix as Tix
(Pdb) tbreak 13
Breakpoint 1 at d:\works\python\test0.py:13
(Pdb) cont
Deleted breakpoint 1 at d:\works\python\test0.py:13
> d:\works\python\test0.py(13)()
-> root.mainloop()
(Pdb) !c['value']
'0'
(Pdb) !demo_maker.get()
'0'
(Pdb) quit

Anyone can help?

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


Re: tkinter.tix "Control" widget don't work with StringVar?

2019-06-01 Thread Terry Reedy

On 6/1/2019 9:28 PM, jf...@ms4.hinet.net wrote:

Below is a simplified version of the sample script downloaded from its package.
When run it, the entry field display '0' instead of 'P&W'.
PS. I am using Python 3.4.4, Windows 32bit

test0.py
  1 from tkinter import tix as Tix
  2
  3 root = Tix.Tk()
  4
  5 demo_maker = Tix.StringVar()
  6 demo_maker.set('P&W')
  7
  8 c = Tix.Control(root, label='Engine Maker: ',
  9variable=demo_maker,
10options='entry.width 10 label.width 20 label.anchor e')
11 c.pack(side=Tix.TOP, anchor=Tix.W)
12
13 root.mainloop()


Line numbers interfere with copy and paste.

Control or Spinbox controls a number that can be increased or decreased 
with the arrows.  You can use a number string like '33' or Intvar or 
Floatvar.


Note that tix is unmaintained, deprecated, and generally not advised for 
new code (or new users).


--
Terry Jan Reedy

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


Re: tkinter.tix "Control" widget don't work with StringVar?

2019-06-01 Thread MRAB

On 2019-06-02 02:28, jf...@ms4.hinet.net wrote:

Below is a simplified version of the sample script downloaded from its package.
When run it, the entry field display '0' instead of 'P&W'.
PS. I am using Python 3.4.4, Windows 32bit

test0.py
  1 from tkinter import tix as Tix
  2
  3 root = Tix.Tk()
  4
  5 demo_maker = Tix.StringVar()
  6 demo_maker.set('P&W')
  7
  8 c = Tix.Control(root, label='Engine Maker: ',
  9variable=demo_maker,
10options='entry.width 10 label.width 20 label.anchor e')
11 c.pack(side=Tix.TOP, anchor=Tix.W)
12
13 root.mainloop()


I run it under pdb, try to figure out where the problem is:

D:\Works\Python>py -m pdb test0.py

d:\works\python\test0.py(1)()

-> from tkinter import tix as Tix
(Pdb) tbreak 13
Breakpoint 1 at d:\works\python\test0.py:13
(Pdb) cont
Deleted breakpoint 1 at d:\works\python\test0.py:13

d:\works\python\test0.py(13)()

-> root.mainloop()
(Pdb) !c['value']
'0'
(Pdb) !demo_maker.get()
'P&W'
(Pdb) quit

If I change line 8 to "c = Tix.Control(root, label='Engine Maker: ', 
value='P&W',", the result is very interest:

D:\Works\Python>py -m pdb test0.py

d:\works\python\test0.py(1)()

-> from tkinter import tix as Tix
(Pdb) tbreak 13
Breakpoint 1 at d:\works\python\test0.py:13
(Pdb) cont
Deleted breakpoint 1 at d:\works\python\test0.py:13

d:\works\python\test0.py(13)()

-> root.mainloop()
(Pdb) !c['value']
'0'
(Pdb) !demo_maker.get()
'0'
(Pdb) quit

Anyone can help?


From the documentation:

"""class tkinter.tix.Control
The Control widget is also known as the SpinBox widget. The user can 
adjust the value by pressing the two arrow buttons or by entering the 
value directly into the entry. The new value will be checked against the 
user-defined upper and lower limits."""


In other words, the widget that you're using is for entering a _number_; 
you can click the up and down buttons to change its value. You usually 
use it with tix.IntVar.


You're using it with tix.StringVar, which is for strings, and because 
it's unable to interpret the value as a number, it's pretending that 
it's 0 instead. You can, however, set it to, say, '1', or '01', and the 
widget will then show the number 1.

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


Re: tkinter.tix "Control" widget don't work with StringVar?

2019-06-01 Thread jfong
MRAB於 2019年6月2日星期日 UTC+8上午10時18分36秒寫道:
> On 2019-06-02 02:28, jf...@ms4.hinet.net wrote:
> > Below is a simplified version of the sample script downloaded from its 
> > package.
> > When run it, the entry field display '0' instead of 'P&W'.
> > PS. I am using Python 3.4.4, Windows 32bit
> > 
> > test0.py
> >   1 from tkinter import tix as Tix
> >   2
> >   3 root = Tix.Tk()
> >   4
> >   5 demo_maker = Tix.StringVar()
> >   6 demo_maker.set('P&W')
> >   7
> >   8 c = Tix.Control(root, label='Engine Maker: ',
> >   9variable=demo_maker,
> > 10options='entry.width 10 label.width 20 label.anchor e')
> > 11 c.pack(side=Tix.TOP, anchor=Tix.W)
> > 12
> > 13 root.mainloop()
> > 
> > 
> > I run it under pdb, try to figure out where the problem is:
> > 
> > D:\Works\Python>py -m pdb test0.py
> >> d:\works\python\test0.py(1)()
> > -> from tkinter import tix as Tix
> > (Pdb) tbreak 13
> > Breakpoint 1 at d:\works\python\test0.py:13
> > (Pdb) cont
> > Deleted breakpoint 1 at d:\works\python\test0.py:13
> >> d:\works\python\test0.py(13)()
> > -> root.mainloop()
> > (Pdb) !c['value']
> > '0'
> > (Pdb) !demo_maker.get()
> > 'P&W'
> > (Pdb) quit
> > 
> > If I change line 8 to "c = Tix.Control(root, label='Engine Maker: ', 
> > value='P&W',", the result is very interest:
> > 
> > D:\Works\Python>py -m pdb test0.py
> >> d:\works\python\test0.py(1)()
> > -> from tkinter import tix as Tix
> > (Pdb) tbreak 13
> > Breakpoint 1 at d:\works\python\test0.py:13
> > (Pdb) cont
> > Deleted breakpoint 1 at d:\works\python\test0.py:13
> >> d:\works\python\test0.py(13)()
> > -> root.mainloop()
> > (Pdb) !c['value']
> > '0'
> > (Pdb) !demo_maker.get()
> > '0'
> > (Pdb) quit
> > 
> > Anyone can help?
> > 
>  From the documentation:
> 
> """class tkinter.tix.Control
> The Control widget is also known as the SpinBox widget. The user can 
> adjust the value by pressing the two arrow buttons or by entering the 
> value directly into the entry. The new value will be checked against the 
> user-defined upper and lower limits."""
> 
> In other words, the widget that you're using is for entering a _number_; 
> you can click the up and down buttons to change its value. You usually 
> use it with tix.IntVar.
> 
> You're using it with tix.StringVar, which is for strings, and because 
> it's unable to interpret the value as a number, it's pretending that 
> it's 0 instead. You can, however, set it to, say, '1', or '01', and the 
> widget will then show the number 1.

From the documents, it sounds that this widget was designed for number only. 
But the original example Control.py from 
https://svn.python.org/projects/stackless/trunk/Demo/tix/samples/ works on 
string either by changing its button command. The only thing bothers me is that 
why it fails at the start-up? and I can't figure out the reason:-(
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Checking support for network connections from Python client to IPv6 server

2019-06-01 Thread Markus Elfring
> "Handled transparently" means that an ipv6 server can handle connections
> from ipv4 clients without doing anything special.

It is nice if this conversion is working.


> They just appear to come from a specific IPv6 address range.

I got expected connections by my small script “socket-send_test_data1.tcl”.


>> Under which circumstances will the Python programming interfaces
>> support the direct usage of the identification “::1”?
>
> I'm not sure I understand the question. They do.

How would like to explain the error message “socket.gaierror: [Errno -9]
Address family for hostname not supported” on my Linux test system then?

Regards,
Markus
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Checking support for network connections from Python client to IPv6 server

2019-06-01 Thread Cameron Simpson

On 02Jun2019 07:14, Markus Elfring  wrote:

"Handled transparently" means that an ipv6 server can handle connections
from ipv4 clients without doing anything special.


It is nice if this conversion is working.



They just appear to come from a specific IPv6 address range.


I got expected connections by my small script “socket-send_test_data1.tcl”.



Under which circumstances will the Python programming interfaces
support the direct usage of the identification “::1”?


I'm not sure I understand the question. They do.


How would like to explain the error message “socket.gaierror: [Errno -9]
Address family for hostname not supported” on my Linux test system 
then?


Can you supply a tiny standalone piece of code demonstrating this error 
please? I've dug through the thread and can't see one.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list