Phyton

2016-03-06 Thread Diego ...
Hello! I have a question in an exercise that says : Write an expression to 
determine whether a person should or should not pay tax . Consider paying tax 
people whose salary is greater than R $ 1,200.00

I do not know how to mount the logical expression !!!

It's like:

salary = 1250
tax = Not True
salary > 1200 or not tax 

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


suppress pop up windwo

2007-08-03 Thread diego
I'm automating the generation of PDF out of Excel sheets through
win32com.

I nearly accomplished everything I wanted, but one problem is still
left:
when I calling the print job through following code:

xl.Selection.PrintOut(Copies=1,Collate=True)

then a window pops up, where I have to input the name of the pdf I
want to generate.
Is there way to pass this filename to this window?



(I'm using 'Jaws PDF Creator" as printer.)

Thanks in advance for your help!

Diego

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


Problem with win32pipe.popen2

2007-01-15 Thread diego
I'm trying to understand how popen2 works. Found in this group, that
popen2.popen2 can cause trouble so i chose win32pipe.popen2.

have a look a the listing of 2 files:
ekmain.py:
**
import win32pipe

(stdin1, stdout1) = win32pipe.popen2("test1.py")
stdin1.write("1\n")
print stdout1.readlines() # This will print the result.
**

test1.py:
**
a=raw_input("a=")
print "***a=",a
print "finished!"
**


i do not understand, why ekmain.py produces only following output:
['a=']

why is the stdin1.write("1\n") command ignored?

i tried to find an answer in this group by searching through existing
article, but i had no success.

tanks for you help!


ernst
p.s.: i working with python 2.3 on win2000.

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


Connecting to Python COM server from Excel VBA does not work

2009-12-10 Thread diego
I ran this script:
---
class Example(object):
_public_methods_ = ['Add','Mul']
_reg_progid_ = 'MyPython.Example'
_reg_clsid_ = '{E39ECD8C-7FAF-48B0-B914-1202319499D4}'

def Add(self,a,b): return a+b

def Mul(self,a,b): return a*b

if __name__ == '__main__':
import win32com.server.register
win32com.server.register.UseCommandLine(Example)
-
connecting to this COM server works with following VBS-script:
-
Set ex = CreateObject("MyPython.Example")
msgbox ex.Add(1, 2)
-

when i run following VBA script in excel
-
Sub Testit()
Set ex = CreateObject("MyPython.Example")
MsgBox ex.Add(1, 2)
End Sub
-

i get the error:
Run-time error '-2137024770 (8007007e)':
Automation error
The specified module could not be found



Any ideas what the problem could be?
Already searched a long time for solutions but did not find any

thanks,
diego
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Connecting to Python COM server from Excel VBA does not work

2009-12-10 Thread diego
On 10 Dez., 11:52, "Michel Claveau -
MVP" wrote:
> Hi !
>
> Warning with lower/uppercases!
> Try to make two versions of your methods (ex.: "add" & "ADD"), for study.
>
> @+
> --
> MCI


The error comes already at the first line of Excel/VBA code:
Set ex = CreateObject("MyPython.Example")


rgds,e
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Connecting to Python COM server from Excel VBA does not work

2009-12-10 Thread diego
On 10 Dez., 11:52, "Michel Claveau -
MVP" wrote:
> Hi !
>
> Warning with lower/uppercases!
> Try to make two versions of your methods (ex.: "add" & "ADD"), for study.
>
> @+
> --
> MCI


The error comes already at the first line of Excel/VBA code:
Set ex = CreateObject("MyPython.Example")


rgds,e
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Connecting to Python COM server from Excel VBA does not work

2009-12-10 Thread diego
the problem was that i had never installed python on my workstation.
just had a Python25 folder with a batch-file that was adjustin the
PATH and executing %PYTHONHOME%python.exe
installed Python properly and now everything works fine
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: learnpython.org - an online interactive Python tutorial

2011-04-21 Thread Diego Arias
On Thu, Apr 21, 2011 at 8:20 PM, Dan Stromberg  wrote:

>
> On Thu, Apr 21, 2011 at 9:13 AM, MRAB  wrote:
>
>> On 21/04/2011 15:14, Westley Martínez wrote:
>>
>>> On Thu, Apr 21, 2011 at 05:19:29PM +1000, Chris Angelico wrote:
>>>
 On Thu, Apr 21, 2011 at 5:10 PM, Algis Kabaila
  wrote:

> False: Python IS strongly typed, without doubt (though the
> variables are not explicitly declared.)
>

 Strongly duck-typed though. If I create a class that has all the right
 members, it can simultaneously be a file, an iterable, a database, and
 probably even a web browser if it feels like it. Is that strong typing
 or not?

 Chris Angelico
 --
 http://mail.python.org/mailman/listinfo/python-list

>>>
>>> It's strong typing.  Python does not implicitly convert types.  Weak
>>> typing is
>>> when I can do 1 + "1" and get 2.
>>>
>>
>> It could be argued that it does implicit convert for some numeric
>> types, eg int to float when needed.
>
>
> Yes, it'll silently promote int to float, int to Decimal, and also almost
> anything can be used in a Boolean context.  No other exceptions to strong
> typing come to mind...
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
> Hi:

Really nice site, keep it going


-- 
Still Going Strong!!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to replace an instance method?

2022-09-21 Thread Diego Souza
Another possibility would be to use a lambda function or a callable
object. This adds an overhead but would also allow you to inject new
parameters that go into the function call. It also does not require
any extra import.

obj.old_method_name = lambda *a, **kw: new_method_name(obj, *a, **kw)

A full example goes like this:

class C:

def __init__(self):
self.value = 21

def get(self):
return self.value

def new_get(self):
return self.value * 2

obj = C()
print(obj.get())
obj.get = lambda *a, **kw: new_get(obj, *a, **kw)
print(obj.get())

This would first output 21 and then 42.

--

What you are trying to do requires more than just replacing the
function _convert_cell. By default, OpenpyxlReader loads the workbook
in read_only mode, discarding all links. This means that the cell
object present in _convert_cell has no hyperlink attribute. There is
no option to make it load the links. To force it to be loaded, we need
to replace load_workbook as well. This method asks openpyxl to load
the workbook, deciding whether it will discard the links or not.

The second problem is that as soon as you instantiate an ExcelFile
object it will instantiate an OpenpyxlReader and load the file.
Leaving you with no time to replace the functions. Happily, ExcelFile
gets the engine class from a static dictionary called _engines. This
means that we can extend OpenpyxlReader, overwrite those two methods
and replace the reference in ExcelFile._engines. The full source is:

import pandas as pd

class MyOpenpyxlReader(pd.ExcelFile.OpenpyxlReader):

def load_workbook(self, filepath_or_buffer):
from openpyxl import load_workbook
return load_workbook(
filepath_or_buffer,
read_only=False,
data_only=False,
keep_links=True
)

def _convert_cell(self, cell, convert_float: bool):
value = super()._convert_cell(cell, convert_float)
if cell.hyperlink is None:
return value
else:
return (value, cell.hyperlink.target)


pd.ExcelFile._engines["openpyxl"] = MyOpenpyxlReader
df = pd.read_excel("links.xlsx")
print(df)

The source above worked on python 3.8.10, pandas 1.5.0, and openpyxl
3.0.10. The output for a sample xlsx file with the columns id, a page
name (with links), and the last access is shown next. The first
element in the second column's output tuple is the cell's text and the
second element is the cell's link:

id
  page   last access
0   1 (google, https://www.google.com/)  2022-04-12
1   2  (gmail, https://gmail.com/)  2022-02-06
2   3  (maps, https://www.google.com/maps)  2022-02-17
3   4  (bbc, https://bbc.co.uk/)  2022-08-30
4   5 (reddit, https://www.reddit.com/)  2022-12-02
5   6(stackoverflow, https://stackoverflow.com/)  2022-05-25

--

Should you do any of this? No.

1. What makes a good developer is his ability to create clear and
maintainable code. Any of these options are clearly not clear,
increase cognitive complexity, and reduce reliability.
2. We are manipulating internal class attributes and internal methods
(those starting with _). Internal elements are not guaranteed to stay
there over different versions, even minor updates. You should not
manipulate them unless you are working on a fixed library version,
like implementing tests and checking if the internal state has
changed, hacking it, or debugging. Python assumes you will access
these attributes wisely.
3. If you are working with other developers and you commit this code
there is a huge chance another developer is using a slightly different
pandas version that misses one of these elements. You will break the
build, your team will complain and start thinking you are a naive
developer.
4. Even if you adapt your code for multiple pandas versions you will
end up with multiple ifs and different implementations. You don't want
to maintain this over time.
5. It clearly takes more time to understand pandas' internals than
writing your reader using openpyxl. It is not cumbersome, and if it
changes the execution time from 20ms to 40ms but is much more reliable
and maintainable we surely prefer the latter.

The only scenario I see in which this would be acceptable is when you
or your boss have an important presentation in the next hour, and you
need a quick fix to make it work in order to demonstrate it. After the
presentation is over and people have validated the functionality you
should properly implement it.

Keep It Simple and Stupid (KISS)

-- 
Diego Souza
Wespa Intelligent Systems
Rio de Janeiro - Brasil

On Mon, Sep 19, 2022 at 1:00 PM  wrote:
>
>
> From: "Weatherby,Gerard" 
> Date: Mon, 19 Sep 2

RE: Asynchronous execution of synchronous functions

2022-09-26 Thread Diego Souza
Did you check the ThreadPoolExecutor or the ProcessPoolExecutor? They
won't give you atomic writes unless you add a Lock or a Condition, but
they will execute your code in another thread or process.

https://docs.python.org/3/library/concurrent.futures.html#threadpoolexecutor
https://docs.python.org/3/library/concurrent.futures.html#processpoolexecutor

Keep in mind that Python's threads have a global interpreter lock
(GIL) that prevents full parallelism. Processes work as expected, but
require IPC and pickable objects in and out.

-- 
Diego Souza
Wespa Intelligent Systems
Rio de Janeiro - Brasil


On Mon, Sep 26, 2022 at 1:01 PM  wrote:
> From: Axy 
> To: Python List 
> Date: Mon, 26 Sep 2022 12:17:47 +0100
> Subject: Asynchronous execution of synchronous functions
> Hi there,
>
> is there a library to call functions in context of a thread? For
> example, as in asyncsqlite which has a thread and a queue I mean has
> anyone generalized such an approach already?
>
> If not, I'll do it myself, no problem.
>
> It's a kind of tiny stuff, like atomicwrites, which is quite difficult
> to dig out with modern search engines that have already rolled down to
> hell a decade ago.
>
> Axy.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Multithreading? How?

2023-05-12 Thread Diego Souza
serial_writer.write(data)
  else:log.error(f'Unknown action for
IotWriter - action={action}, data={data}')except:
  traceback.print_exc(file=sys.stdout)
log.warning("Terminating IotWriter")serial_writer.terminate()*


I do not include the source for a MqttReceiver and MqttWriter as they are
very similar, in structure, to IotWriter and MqttWriter. The code below is
for the Gateway class. It initializes all readers and writers. Following
that, it will wait for input messages and process them adequately. You
could add as many events as you need. I used two to illustrate.





































































*class Gateway(Thread):def __init__(self):super().__init__()
self.queue_master = Queue()self.done = False
self.start()def run(self):log.info
<http://log.info>("Starting Gateway")while not self.done:
  try:self.iot_reader  =
IotReader(self.queue_master)self.iot_writer  = IotWriter()
  self.mqtt_reader =
MqttReader(self.queue_master)self.mqtt_writer =
MqttWriter()log.info <http://log.info>(f"Starting
{self.__class__.__name__}")while not
self.done:try:action, data =
self.queue_master.get()if
action in 'on_mqtt_event':
self.on_mqtt_event(data)
elif action == 'on_iot_event':
self.on_iot_event(data)elif
action == 'terminate':break
else:
log.error(f'Unknown action, action={action}, data={data}')
  except:log.error("Error
during message parsing")
traceback.print_exc(file=sys.stdout)except:
log.error("Error during gateway configuration")
traceback.print_exc(file=sys.stdout)
self.iot_reader.terminate()self.iot_writer.terminate()
self.mqtt_reader.terminate()self.mqtt_writer.terminate()
self.iot_reader.join()self.iot_writer.join()
self.mqtt_reader.join()self.mqtt_writer.join()
log.warning('Terminating Gateway')def terminate(self):
self.done = Trueself.queue_master.put(('terminate', None))
def on_iot_event(self, data):log.info <http://log.info>(f'Event
from iot device, forwarding to mqtt, data={data}')
self.mqtt_writer.send(data)def on_mqtt_event(self, data):
log.info <http://log.info>(f'Event from iot device, forwarding to iot,
data={data}')self.iot_writer.send(data)*


I started the Gateway using the code below. It calls the method terminate
when I press Ctrl+C. This event could also come from the MQTT server or
anywhere else.




















*gateway = Gateway()# Your main thread is free here. You could start a
webserver and display # a dashboard. Or wait, like below.try:
gateway.join()except KeyboardInterrupt:log.info
<http://log.info>("Sending terminate command...")
gateway.terminate()try:gateway.join()except KeyboardInterrupt:
log.info <http://log.info>("Killing the app...")sys.exit(0)
passlog.info <http://log.info>("Bye!")*


If you want to check the full code, a small gist in the link below:
*https://gist.github.com/diegofps/87945a0c3e800c747f3af07833ff6b7e
<https://gist.github.com/diegofps/87945a0c3e800c747f3af07833ff6b7e>*


You also mentioned discovering the device status and sending it back
through MQTT. I can see two approaches to this. The first approach is to
cache the status emitted from the device. This is fine if the data is small
enough to keep in the gateway memory. Then, I would send it back through
MQTT immediately. The second approach is to forward the request to the
device. The device will later respond to your query with the original
question and response. You likely need the question as you need to remember
what you need to do with it now. It is stateless. You could also mix these
two approaches and cache the state for a certain amount of time. After
that, it would expire, and you would ask the device again.

This is an overview of how I implement it nowadays. I am sure other people
may have different strategies and ideas to improve it.

Best,
Diego




On Fri, Apr 28, 2023 at 1:10 PM pozz  wrote:

> I need to develop a Python application that is a sort of gateway between
> to networks: a "serial bus" network (think of a serial port or a USB
> connection) and a MQTT connection (in my case, it's AWS IoT service).
>
> On the bus, a proprietary protocol is implemented. From the bus, the app
>

Mock object bug with assert_not_called

2016-12-27 Thread Diego Vela
Dear all,

>From reading the documentation it seemed like this is the place to post a
bug.  If not please let me know where is the proper place to do so.

Bug:
For mock objects created using the @patch decorator the following methods
are inconsistent.
assert_not_called,
assert_called_with

Steps
Create a mock object using the @patch decorator for a function.
call a function that that calls the mocked function.
check assert_not_called and assert_called with.

Thank you for your time.

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


Re: Re: Mock object bug with assert_not_called (Steve D'Aprano)

2016-12-28 Thread Diego Vela
Re: mock bug.

Python 2.7.8


I'll provide a sketch of the code since it is from work and I'm not allowed
to share it directly.

Sketch of Code:
@patch('emails.emails.render_to_string')
def test_send_email(self, render):
context = {
  'key': value
}
emails.send_email() # calls render_to_string
render.assert_any_call(
 'template.txt',
 context
 )
render.assert_not_called()


Expected behavior is that one of the asserts should raise an exception.
The assert_not_called() should assert that the mocked method was not called
at all.  The assert_any_call(vars) asserts there is at least one call with
the given args.  If neither throws an exception then this is a
contradiction because the mocked object, render in this case, has asserted
that there are no calls and that there is at least one call.

Is this sufficient?  I'm not so sure, this is my first time.  Thanks for
the help.

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


Change OnScreen Keyboard StringVar (Show linked to one Entry)

2016-04-10 Thread Diego Lelis
Hi guys, im having a little problem to make the StringVar Linked to my OnScreen 
Keyboard Change when the user click in one Entry.

Here's my code:
from tkinter import *

Begin Code___

def frame(root, side):
w = Frame(root)
w.pack(side=side, expand=YES, fill=BOTH)
return w

def button(root, side, text, command=None):
w = Button(root, text=text, command=command)
w.pack(side=side, expand=YES, fill=BOTH)
return w


class Keyboard(Frame):
def __init__(self):
Frame.__init__(self)
self.option_add('*Font', 'Verdana 12 bold')
self.pack(expand=YES, fill=BOTH)
self.master.title('Simple Screen Keyboard')

def detect_Focus(event):
print ('Change selected_display to the display correspondent to 
selected entry')

display_1 = StringVar()
entry_1 = Entry(self, relief=SUNKEN, textvariable=display_1)
entry_1.bind('', detect_Focus)
entry_1.pack(side=TOP, expand=YES, fill=BOTH)


display_2 = StringVar()
entry_2 = Entry(self, relief=SUNKEN, textvariable=display_2)
entry_2.bind('', detect_Focus)
entry_2.pack(side=TOP, expand=YES, fill=BOTH)

selected_display = display_1

for key in ("123", "456", "789", "-0."):
keyF = frame(self, TOP)
for char in key:
button(keyF, LEFT, char,
   lambda w=selected_display, c=char: w.set(w.get() + c))

if __name__ == '__main__':
Keyboard().mainloop()


End Code___


When i run the detect_Focus Function, i wanted change the selected_display, to 
make the user change the entry2(display_2), using my on screen keyboard.

Thanks in advance!
-- 
https://mail.python.org/mailman/listinfo/python-list


Change Windows Tkinter after some time

2016-04-10 Thread Diego Lelis
I need to make a change between windows, after some time. But i am have a 
little bit of trouble making my code work: My windows change only when i click 
on button, i tried to put lambda in my command and also don't work.

import tkinter as tk   # python3
#import Tkinter as tk   # python
import datetime
TITLE_FONT = ("Helvetica", 18, "bold")
time_start = datetime.datetime.now()
delta_time = datetime.timedelta(seconds = 5)
class SampleApp(tk.Tk):

def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)

# the container is where we'll stack a bunch of frames
# on top of each other, then the one we want visible
# will be raised above the others
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}

for F in (StartPage, TimePage):
page_name = F.__name__
frame = F(container, self)
self.frames[page_name] = frame

# put all of the pages in the same location;
# the one on the top of the stacking order
# will be the one that is visible.
frame.grid(row=0, column=0, sticky="nsew")

self.show_frame("StartPage")

def show_frame(self, page_name):
'''Show a frame for the given page name'''
frame = self.frames[page_name]
frame.tkraise()


class StartPage(tk.Frame):
def __init__(self, parent, controller):

tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is the start page", font=TITLE_FONT)
label.pack(side="top", fill="x", pady=10)

button1 = tk.Button(self, text="Go to Time Page",
command=lambda: 
controller.show_frame(self.start_Counting()) )
button1.pack()

def start_Counting(self):
global time_start
time_start = datetime.datetime.now()
return 'TimePage'

class TimePage(tk.Frame):

def __init__(self, parent, controller):
global delta_time
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is Time Page", font=TITLE_FONT)
label.pack(side="top", fill="x", pady=10)
self.time_exit = tk.StringVar()
self.time_exit.set('%s' %datetime.datetime.now())
label2 = tk.Label(self, text=self.time_exit, font=TITLE_FONT)
label2.pack(side="top", fill="x", pady=10)
button = tk.Button(self, text="Go to the start page",
   command=lambda: controller.show_frame("StartPage"))
button.pack()

def update_Page(self):
global time_start, delta_time
#print('Executou o atualizar')
time_until = delta_time - (datetime.datetime.now() - time_start)
self.time_exit.set('%s' %time_until)
if time_until <= 0:
self.controller.show_frame('StartPage') # Go to the start_page 
after 5 seconds
self.after(1000, update_Page)

if __name__ == "__main__":
app = SampleApp()
app.mainloop()
-- 
https://mail.python.org/mailman/listinfo/python-list


mask and proper index

2019-02-03 Thread diego . avesani
Dear all,

I am trying to apply a mask to my dataframe:

mask = (df['datatime'] > start_date) & (df['datatime'] <= end_date)
df = df.loc[mask]


It seems to work pretty well. 

After that I crate the cumulative of its element as:


PP_cumPP = np.cumsum(df[PP_station])


However, I am not able to compute PP_cumPP last element. Indeed, when I do

 len(PP_cumPP)

I get 

8783

and when I try to do:

PP_cumPP[len(PP_cumPP)-1]

I get an error.


What I am doing wrong?

Thanks a lot for any kind of help

Diedro

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


Re: mask and proper index

2019-02-04 Thread Diego Avesani


Dear all, Dear Peter,

thanks for you suggestions. Next time, I will try to set-up a proper example in 
order to post it and explain better my problem.
You understood perfectly what was my problem. Thanks a lot, indeed it seems to 
work.

If I can ask, due to the fact that I am new to thins kind of forum. 
In this moment, I have another problem related to the data I am working on. 
Should I write another post?
Should I do something else related to this post?

Thanks a lot again,
you are my lifesaver 






On Sunday, 3 February 2019 16:56:44 UTC+1, Diego Avesani  wrote:
> Dear all,
> 
> I am trying to apply a mask to my dataframe:
> 
> mask = (df['datatime'] > start_date) & (df['datatime'] <= end_date)
> df = df.loc[mask]
> 
> 
> It seems to work pretty well. 
> 
> After that I crate the cumulative of its element as:
> 
> 
> PP_cumPP = np.cumsum(df[PP_station])
> 
> 
> However, I am not able to compute PP_cumPP last element. Indeed, when I do
> 
>  len(PP_cumPP)
> 
> I get 
> 
> 8783
> 
> and when I try to do:
> 
> PP_cumPP[len(PP_cumPP)-1]
> 
> I get an error.
> 
> 
> What I am doing wrong?
> 
> Thanks a lot for any kind of help
> 
> Diedro

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


format number is not recognized in a cycle

2019-02-04 Thread Diego Avesani
Dear all,

I have this dataframe:

datatime,T,RH,PSFC,DIR,VEL10,PREC,RAD,CC,FOG
2012-01-01 06:00,  0.4,100, 911,321,  2.5,  0.0,   0,  0,0
2012-01-01 07:00,  0.8,100, 911,198,  0.8,  0.0,   0, 22,0
2012-01-01 08:00,  0.6,100, 912, 44,  1.2,  0.0,  30, 22,0
2012-01-01 09:00,  3.1, 76, 912, 22,  0.8,  0.0, 134, 44,0
2012-01-01 10:00,  3.4, 77, 912, 37,  0.5,  0.0, 191, 67,0
2012-01-01 11:00,  3.5,100, 912,349,  0.4,  0.0, 277, 44,0
2012-01-01 12:00,  3.6,100, 912, 17,  0.9,  0.0, 292, 22,0
2012-01-01 13:00,  3.5,100, 912, 28,  0.3,  0.0, 219, 44,0
2012-01-01 14:00,  3.3, 68, 912, 42,  0.5,  0.0, 151, 22,0




I would like to plot and analyse different part of it. Consequently I have 
created the following variables in order to manage different period:

start_date = np.array(['2012-01-01 06:00','2013-01-01 06:00','2014-01-01 
06:00'])
end_date   = np.array(['2013-01-01 05:00','2014-01-01 05:00','2015-01-01 
05:00'])

However, if I try to perform the following cycle:

for ii in range(0, 1):   
   pd.read_csv('dati.csv',delimiter=',',header=0,parse_dates=True,
   na_values=-999)
   df['datatime'] = df['datatime'].map(lambda x: datetime.strptime(str(x), 
"%Y-%m-%d %H:%M"))
   #
   mask = (df['datatime'] > start_date[ii]) & (df['datatime'] <= end_date[ii])

I get the following error:

return _get_dtype_type(np.dtype(arr_or_dtype))
  File "/usr/lib/python2.7/dist-packages/numpy/core/_internal.py", line 173, in 
_commastring
(len(result)+1, astr))
ValueError: format number 1 of "2012-01-01 06:00" is not recognized



On the contrary, if I use the simple variables:
start_date = 2012-01-01 06:00
end_date   = 2013-01-01 05:00

without the cycle, it works.

I really do not understand why.

Thanks a lot,
Diego

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


pandas read dataframe and sum all value same month and year

2019-02-04 Thread Diego Avesani
Dear all,

I am reading the following data-frame:

datatime,T,RH,PSFC,DIR,VEL10,PREC,RAD,CC,FOG
2012-01-01 06:00, -0.1,100, 815,313,  2.6,  0.0,   0,  0,0
2012-01-01 07:00, -1.2, 93, 814,314,  4.8,  0.0,   0,  0,0
2012-01-01 08:00,  1.7, 68, 815,308,  7.5,  0.0,  41, 11,0
2012-01-01 09:00,  2.4, 65, 815,308,  7.4,  0.0, 150, 33,0
2012-01-01 10:00,  3.0, 64, 816,305,  8.4,  0.0, 170, 44,0
2012-01-01 11:00,  2.6, 65, 816,303,  6.3,  0.0, 321, 22,0
2012-01-01 12:00,  2.0, 72, 816,278,  1.3,  0.0, 227, 22,0
2012-01-01 13:00, -0.0, 72, 816,124,  0.1,  0.0, 169, 22,0
2012-01-01 14:00, -0.1, 68, 816,331,  1.4,  0.0, 139, 33,0
2012-01-01 15:00, -4.0, 85, 816,170,  0.6,  0.0,  49,  0,0



I read the data frame as:

 df = 
pd.read_csv('dati.csv',delimiter=',',header=0,parse_dates=True,na_values=-999)
   df['datatime'] = df['datatime'].map(lambda x: datetime.strptime(str(x), 
"%Y-%m-%d %H:%M"))
   #
   mask = (df['datatime'] > str(start_date[ii])) & (df['datatime'] <=  
str(end_date[ii]))
   df = df.loc[mask]
   df = df.reset_index(drop=True)

I would to create an array with the sum of all the PREC value in the same month.

I have tried with:

df.groupby(pd.TimeGrouper('M')).sum()

But as always, it seems that I have same problems with the indexes. Indeed, I 
get:
  'an instance of %r' % type(ax).__name__)
TypeError: axis must be a DatetimeIndex, but got an instance of 'Int64Index'

thanks for any kind of help,
Really Really thanks

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


Re: format number is not recognized in a cycle

2019-02-04 Thread Diego Avesani
Dear Peter,

thanks a lot for your patience.


this is the code:

import pandas as pd
import numpy as np
from datetime import datetime


#input:
start_date = np.array(["2012-01-01 06:00",'2013-01-01 06:00','2014-01-01 
06:00'])
end_date   = np.array(["2013-01-01 05:00",'2014-01-01 05:00','2015-01-01 
05:00'])
yearfolder = np.array(['2012','2013','2014'])


for ii in range(0, 1):
   df = 
pd.read_csv('dati.csv',delimiter=',',header=0,parse_dates=True,na_values=-999)
   df['datatime'] = df['datatime'].map(lambda x: datetime.strptime(str(x), 
"%Y-%m-%d %H:%M"))
   mask = (df['datatime'] > start_date[ii]) & (df['datatime'] <=  end_date[ii])
   df = df.loc[mask]



and here a piece of my dati.csv file


datatime,T,RH,PSFC,DIR,VEL10,PREC,RAD,CC,FOG
2012-01-01 06:00, -0.1,100, 815,313,  2.6,  0.0,   0,  0,0
2012-01-01 07:00, -1.2, 93, 814,314,  4.8,  0.0,   0,  0,0
2012-01-01 08:00,  1.7, 68, 815,308,  7.5,  0.0,  41, 11,0
2012-01-01 09:00,  2.4, 65, 815,308,  7.4,  0.0, 150, 33,0
2012-01-01 10:00,  3.0, 64, 816,305,  8.4,  0.0, 170, 44,0
2012-01-01 11:00,  2.6, 65, 816,303,  6.3,  0.0, 321, 22,0
2012-01-01 12:00,  2.0, 72, 816,278,  1.3,  0.0, 227, 22,0
2012-01-01 13:00, -0.0, 72, 816,124,  0.1,  0.0, 169, 22,0
2012-01-01 14:00, -0.1, 68, 816,331,  1.4,  0.0, 139, 33,0
2012-01-01 15:00, -4.0, 85, 816,170,  0.6,  0.0,  49,  0,0
2012-01-01 16:00, -5.6, 92, 816,168,  0.8,  0.0,   0,  0,0
2012-01-01 17:00, -6.4, 96, 817,109,  0.4,  0.0,   0,  0,0
2012-01-01 18:00, -6.9,100, 817,116,  0.6,  0.0,   0,  0,0
2012-01-01 19:00, -7.5,100, 817,127,  0.8,  0.0,   0,  0,0
2012-01-01 20:00, -7.7,100, 817,136,  0.6,  0.0,   0,  0,0
2012-01-01 21:00, -7.7,100, 818,118,  0.7,  0.0,   0,  0,0
2012-01-01 22:00, -7.8,100, 817,130,  0.5,  0.0,   0,  0,0
2012-01-01 23:00, -7.9,100, 816,160,  0.6,  0.0,   0,  0,0
2012-01-02 00:00, -8.3,100, 816,123,  0.6,  0.0,   0,  0,0
2012-01-02 01:00, -8.6,100, 815,119,  0.8,  0.0,   0, 11,0
2012-01-02 02:00, -9.1,100, 814,118,  1.1,  0.0,   0, 33,0



thanks, again, a lot

On Monday, 4 February 2019 15:51:41 UTC+1, Peter Otten  wrote:
> Diego Avesani wrote:
> 
> > Dear all,
> > 
> > I have this dataframe:
> > 
> > datatime,T,RH,PSFC,DIR,VEL10,PREC,RAD,CC,FOG
> > 2012-01-01 06:00,  0.4,100, 911,321,  2.5,  0.0,   0,  0,0
> > 2012-01-01 07:00,  0.8,100, 911,198,  0.8,  0.0,   0, 22,0
> > 2012-01-01 08:00,  0.6,100, 912, 44,  1.2,  0.0,  30, 22,0
> > 2012-01-01 09:00,  3.1, 76, 912, 22,  0.8,  0.0, 134, 44,0
> > 2012-01-01 10:00,  3.4, 77, 912, 37,  0.5,  0.0, 191, 67,0
> > 2012-01-01 11:00,  3.5,100, 912,349,  0.4,  0.0, 277, 44,0
> > 2012-01-01 12:00,  3.6,100, 912, 17,  0.9,  0.0, 292, 22,0
> > 2012-01-01 13:00,  3.5,100, 912, 28,  0.3,  0.0, 219, 44,0
> > 2012-01-01 14:00,  3.3, 68, 912, 42,  0.5,  0.0, 151, 22,0
> > 
> > 
> > 
> > 
> > I would like to plot and analyse different part of it. Consequently I have
> > created the following variables in order to manage different period:
> > 
> > start_date = np.array(['2012-01-01 06:00','2013-01-01 06:00','2014-01-01
> > 06:00'])
> > end_date   = np.array(['2013-01-01 05:00','2014-01-01 05:00','2015-01-01
> > 05:00'])
> > 
> > However, if I try to perform the following cycle:
> > 
> > for ii in range(0, 1):
> >pd.read_csv('dati.csv',delimiter=',',header=0,parse_dates=True,
> >na_values=-999)
> >df['datatime'] = df['datatime'].map(lambda x: datetime.strptime(str(x),
> >"%Y-%m-%d %H:%M"))
> >#
> >mask = (df['datatime'] > start_date[ii]) & (df['datatime'] <=
> >end_date[ii])
> > 
> > I get the following error:
> > 
> > return _get_dtype_type(np.dtype(arr_or_dtype))
> >   File "/usr/lib/python2.7/dist-packages/numpy/core/_internal.py", line
> >   173, in _commastring
> > (len(result)+1, astr))
> > ValueError: format number 1 of "2012-01-01 06:00" is not recognized
> > 
> > 
> > 
> > On the contrary, if I use the simple variables:
> > start_date = 2012-01-01 06:00
> > end_date   = 2013-01-01 05:00
> > 
> > without the cycle, it works.
> > 
> > I really do not understand why.
> 
> Nor do I.
> 
> Also, I cannot run the code above, and when I fill in the missing parts 
> using guesswork I cannot reproduce the error.
> 
> Would you mind posting a small script, inserted via cut and paste into your 
> message, that we can run without any additions?
> 
> You may want to read http://www.sscce.org/ first.

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


Re: format number is not recognized in a cycle

2019-02-04 Thread Diego Avesani
Dear Peter, Deal all,

Trying different options, I manage this solution:

   mask = (df['datatime'] > str(start_date[ii])) & (df['datatime'] <=  
str(end_date[ii]))

As you can notice, I have put str before start_date[ii]) and end_date[ii].

What do you think?

Thanks






On Monday, 4 February 2019 20:00:32 UTC+1, Peter Otten  wrote:
> Diego Avesani wrote:
> 
> > this is the code:
> 
> While the example is fine now it runs without error over here, on rather old 
> versions of pandas (0.13.1) and numpy (1.8.2).
> 
> Therefore I'm out of the debugging cycle for now.

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


Re: pandas read dataframe and sum all value same month and year

2019-02-04 Thread Diego Avesani
Deal all,
following Peter's suggestion,

I put the example code:

import pandas as pd
import numpy as np
from datetime import datetime


#input:
start_date = np.array(["2012-01-01 06:00",'2013-01-01 06:00','2014-01-01 
06:00'])
end_date   = np.array(["2013-01-01 05:00",'2014-01-01 05:00','2015-01-01 
05:00'])
yearfolder = np.array(['2012','2013','2014'])


for ii in range(0, 1):
   df = 
pd.read_csv('dati.csv',delimiter=',',header=0,parse_dates=True,na_values=-999)
   df['datatime'] = df['datatime'].map(lambda x: datetime.strptime(str(x), 
"%Y-%m-%d %H:%M"))
   mask = (df['datatime'] > str(start_date[ii])) & (df['datatime'] <=  
str(end_date[ii]))
   df = df.loc[mask]
   df = df.reset_index(drop=True)
   #
   df.groupby(pd.TimeGrouper('m')).sum()


and the example of file:

datatime,T,RH,PSFC,DIR,VEL10,PREC,RAD,CC,FOG
2012-01-01 06:00,  0.4,100, 911,321,  2.5,  0.0,   0,  0,0
2012-01-01 07:00,  0.8,100, 911,198,  0.8,  0.0,   0, 22,0
2012-01-01 08:00,  0.6,100, 912, 44,  1.2,  0.0,  30, 22,0
2012-01-01 09:00,  3.1, 76, 912, 22,  0.8,  0.0, 134, 44,0
2012-01-01 10:00,  3.4, 77, 912, 37,  0.5,  0.0, 191, 67,0
2012-01-01 11:00,  3.5,100, 912,349,  0.4,  0.0, 277, 44,0
2012-01-01 12:00,  3.6,100, 912, 17,  0.9,  0.0, 292, 22,0
2012-01-01 13:00,  3.5,100, 912, 28,  0.3,  0.0, 219, 44,0
2012-01-01 14:00,  3.3, 68, 912, 42,  0.5,  0.0, 151, 22,0



Hope this could help in finding a way to sum value belonging to the same month.

Thanks again, a lot

Diego





On Monday, 4 February 2019 15:50:52 UTC+1, Diego Avesani  wrote:
> Dear all,
> 
> I am reading the following data-frame:
> 
> datatime,T,RH,PSFC,DIR,VEL10,PREC,RAD,CC,FOG
> 2012-01-01 06:00, -0.1,100, 815,313,  2.6,  0.0,   0,  0,0
> 2012-01-01 07:00, -1.2, 93, 814,314,  4.8,  0.0,   0,  0,0
> 2012-01-01 08:00,  1.7, 68, 815,308,  7.5,  0.0,  41, 11,0
> 2012-01-01 09:00,  2.4, 65, 815,308,  7.4,  0.0, 150, 33,0
> 2012-01-01 10:00,  3.0, 64, 816,305,  8.4,  0.0, 170, 44,0
> 2012-01-01 11:00,  2.6, 65, 816,303,  6.3,  0.0, 321, 22,0
> 2012-01-01 12:00,  2.0, 72, 816,278,  1.3,  0.0, 227, 22,0
> 2012-01-01 13:00, -0.0, 72, 816,124,  0.1,  0.0, 169, 22,0
> 2012-01-01 14:00, -0.1, 68, 816,331,  1.4,  0.0, 139, 33,0
> 2012-01-01 15:00, -4.0, 85, 816,170,  0.6,  0.0,  49,  0,0
> 
> 
> 
> I read the data frame as:
> 
>  df = 
> pd.read_csv('dati.csv',delimiter=',',header=0,parse_dates=True,na_values=-999)
>df['datatime'] = df['datatime'].map(lambda x: datetime.strptime(str(x), 
> "%Y-%m-%d %H:%M"))
>#
>mask = (df['datatime'] > str(start_date[ii])) & (df['datatime'] <=  
> str(end_date[ii]))
>df = df.loc[mask]
>df = df.reset_index(drop=True)
> 
> I would to create an array with the sum of all the PREC value in the same 
> month.
> 
> I have tried with:
> 
> df.groupby(pd.TimeGrouper('M')).sum()
> 
> But as always, it seems that I have same problems with the indexes. Indeed, I 
> get:
>   'an instance of %r' % type(ax).__name__)
> TypeError: axis must be a DatetimeIndex, but got an instance of 'Int64Index'
> 
> thanks for any kind of help,
> Really Really thanks
> 
> Diego

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


Re: format number is not recognized in a cycle

2019-02-04 Thread Diego Avesani
Dear all, Dear Peter,

could you suggest me one?

Thanks a lot,
Diego

On Monday, 4 February 2019 13:58:17 UTC+1, Diego Avesani  wrote:
> Dear all,
> 
> I have this dataframe:
> 
> datatime,T,RH,PSFC,DIR,VEL10,PREC,RAD,CC,FOG
> 2012-01-01 06:00,  0.4,100, 911,321,  2.5,  0.0,   0,  0,0
> 2012-01-01 07:00,  0.8,100, 911,198,  0.8,  0.0,   0, 22,0
> 2012-01-01 08:00,  0.6,100, 912, 44,  1.2,  0.0,  30, 22,0
> 2012-01-01 09:00,  3.1, 76, 912, 22,  0.8,  0.0, 134, 44,0
> 2012-01-01 10:00,  3.4, 77, 912, 37,  0.5,  0.0, 191, 67,0
> 2012-01-01 11:00,  3.5,100, 912,349,  0.4,  0.0, 277, 44,0
> 2012-01-01 12:00,  3.6,100, 912, 17,  0.9,  0.0, 292, 22,0
> 2012-01-01 13:00,  3.5,100, 912, 28,  0.3,  0.0, 219, 44,0
> 2012-01-01 14:00,  3.3, 68, 912, 42,  0.5,  0.0, 151, 22,0
> 
> 
> 
> 
> I would like to plot and analyse different part of it. Consequently I have 
> created the following variables in order to manage different period:
> 
> start_date = np.array(['2012-01-01 06:00','2013-01-01 06:00','2014-01-01 
> 06:00'])
> end_date   = np.array(['2013-01-01 05:00','2014-01-01 05:00','2015-01-01 
> 05:00'])
> 
> However, if I try to perform the following cycle:
> 
> for ii in range(0, 1):   
>pd.read_csv('dati.csv',delimiter=',',header=0,parse_dates=True,
>na_values=-999)
>df['datatime'] = df['datatime'].map(lambda x: datetime.strptime(str(x), 
> "%Y-%m-%d %H:%M"))
>#
>mask = (df['datatime'] > start_date[ii]) & (df['datatime'] <= end_date[ii])
> 
> I get the following error:
> 
> return _get_dtype_type(np.dtype(arr_or_dtype))
>   File "/usr/lib/python2.7/dist-packages/numpy/core/_internal.py", line 173, 
> in _commastring
> (len(result)+1, astr))
> ValueError: format number 1 of "2012-01-01 06:00" is not recognized
> 
> 
> 
> On the contrary, if I use the simple variables:
> start_date = 2012-01-01 06:00
> end_date   = 2013-01-01 05:00
> 
> without the cycle, it works.
> 
> I really do not understand why.
> 
> Thanks a lot,
> Diego

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


Different results for different versions of urllib2

2012-04-20 Thread Diego Manenti Martins
Hi.
Anybody knows the data is sent in a different way for Python 2.5, 2.6
and 2.7 using this code:

>>> import urllib2
>>> url = 'http://server.com/post_image?tid=zoV6LJ'
>>> f = open('test.jpg')
>>> data = f.read()
>>> res = urllib2.urlopen(url, data)

It works the same way for python2.5 and python2.6 but not for python2.7

I checked the sent data with WireShark and it sends the data in a
different way. I'm not an expert I just see it's different :)
It might be a server problem although I think the lib should behave
equals for all versions.

Thoughts?
Thank you all!
-- 
diego
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Different results for different versions of urllib2

2012-04-20 Thread Diego Manenti Martins
On Fri, Apr 20, 2012 at 10:08 PM, Dave Angel  wrote:
> On 04/20/2012 06:47 PM, Diego Manenti Martins wrote:
>> Hi.
>> Anybody knows the data is sent in a different way for Python 2.5, 2.6
>> and 2.7 using this code:
>>
>>>>> import urllib2
>>>>> url = 'http://server.com/post_image?tid=zoV6LJ'
>>>>> f = open('test.jpg')
>>>>> data = f.read()
>>>>> res = urllib2.urlopen(url, data)
>> It works the same way for python2.5 and python2.6 but not for python2.7
>>
>> I checked the sent data with WireShark and it sends the data in a
>> different way. I'm not an expert I just see it's different :)
>> It might be a server problem although I think the lib should behave
>> equals for all versions.
>>
>> Thoughts?
>> Thank you all!
> I'd be surprised it works at all.  A jpeg is binary, so you should be
> using the following form:
>
>    f = open('test.jpg', 'rb')

ok. I just forget it when writing the email, but get the same result.

-- 
diego
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: Different results for different versions of urllib2

2012-04-20 Thread Diego Manenti Martins
On Fri, Apr 20, 2012 at 11:09 PM, Dave Angel  wrote:
> You forgot to include the list in your response.  I don't normally
> respond to private messages, but I'll make an exception.

Sorry about that and thanks.

>> On 04/20/2012 06:47 PM, Diego Manenti Martins wrote:
>>> Hi.
>>> Anybody knows the data is sent in a different way for Python 2.5, 2.6
>>> and 2.7 using this code:
>>>
>>>>>> import urllib2
>>>>>> url = 'http://server.com/post_image?tid=zoV6LJ'
>>>>>> f = open('test.jpg')
>>>>>> data = f.read()
>>>>>> res = urllib2.urlopen(url, data)
>>> It works the same way for python2.5 and python2.6 but not for python2.7
>>>
>>> I checked the sent data with WireShark and it sends the data in a
>>> different way. I'm not an expert I just see it's different :)
>>> It might be a server problem although I think the lib should behave
>>> equals for all versions.


> 1) Don't retype it, copy/paste it.  Far too much time is wasted finding
> bugs which were just introduced when people compose their emails by
> retyping stuff.   Post exactly what you ran.

I copied it. just changed the server name. It's the code I ran and
works on 2.6 and not on 2.7
Even don't specifying the 'rb' when open the file, that code works on python 2.6

> 2) Be specific about what behavior has you bothered.  You say it's
> "different".  From that I could conclude that in Python 2.6 it prints
> "April Fool" and in Python 2.7 it blows up your machine.

The problem is that I don't know what is wrong. I don't have access to
the server I'm sending data. I just get a server error when running
the code with python 2.7
I just wonder if someone get some behavior like this or know if
something changed on urllib2 and libs that are used on it.

Thank you for your time.

-- 
diego
-- 
http://mail.python.org/mailman/listinfo/python-list


Documentación desde la terminal de comandos.

2012-06-07 Thread Diego Uribe Gamez
Una pregunta, como puedo listar todas las librerías que puedo importar a un
.py? y de sus clases? en la terminal de Linux Debian, algo así como cuando
listo todos los programas usando "# aptitude search nombre"

Se que entro a otra terminal usando "# Python"

Gracias

-- 
 *Diego Alonso Uribe Gamez*
--

*Desarrollador web*

Twitter: @DiegoUG <http://www.twitter.com/DiegoUG>

Google+: http://gplus.to/diegoug
--
-- 
http://mail.python.org/mailman/listinfo/python-list


Autoglade

2007-10-10 Thread Diego Torres Milano
I've been working on a python based tool named autoglade that could be
of help to simplify application development using glade as the interface
designer.
There is a lot of room for improvement but it's pretty usable right now.

You can download autoglade from http://sourceforge.net/projects/autoglade.

A basic tutorial can be found in the wiki:
http://autoglade.wiki.sourceforge.net/autoglade+tutorial+-+first+steps

This tutorial shows how you can create "applications" only from the
glade definition, no programming. A great companion for tools like
nautilus actions.

Comments, suggestions, critics, bugs, fixes, etc are gladly welcome.


-- 
Diego Torres Milano

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


Error when executing the library reference echo server example

2007-12-10 Thread diego . martin . a
Hi. Python newbie speaking,

I've copy/pasted the example of the echo server that comes in the IDLE
documentation ("Python Library Reference" section 17.2.3) to see how
the sockets work. The only change I've made is in the host address
which I've set to 'localhost' in the client. You can see the complete
code below the message.

When I run it I get the following error:
 Traceback (most recent call last):
  File "C:\Python25\eclient.py", line 11, in 
  data = s.recv(1024)
 error: (10053, 'Software caused connection abort')

Is the example wrong? In this case, Where can I find a working
example? Have I messed up the example putting 'localhost'? (don't
think so, because I tried with '127.0.0.1' and I got the same error).
And the big one, Why I get the error and how can I avoid it in future
applications?

Lot of thanks in advance!!

---CODE---
# Echo server program
import socket

HOST = '' # Symbolic name meaning the local host
PORT = 50001  # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(10)
conn, addr = s.accept()
print 'Connected by', addr
while 1:
data = conn.recv(1024)
if not data: break
conn.send(data)
conn.close()
___

# Echo client program
import socket

HOST = 'localhost'# The remote host
PORT = 50001  # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send('Hello, world')
data = s.recv(1024)
s.close()
print 'Received', repr(data)

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


Re: Error when executing the library reference echo server example

2007-12-10 Thread diego . martin . a
On Dec 10, 1:48 pm, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:
> On Mon, 10 Dec 2007 04:16:03 -0800 (PST), [EMAIL PROTECTED] wrote:
> >Hi. Python newbie speaking,
>
> >I've copy/pasted the example of the echo server that comes in the IDLE
> >documentation ("Python Library Reference" section 17.2.3) to see how
> >the sockets work. The only change I've made is in the host address
> >which I've set to 'localhost' in the client. You can see the complete
> >code below the message.
>
> >When I run it I get the following error:
> > Traceback (most recent call last):
> >  File "C:\Python25\eclient.py", line 11, in 
> >  data = s.recv(1024)
> > error: (10053, 'Software caused connection abort')
>
> >Is the example wrong? In this case, Where can I find a working
> >example? Have I messed up the example putting 'localhost'? (don't
> >think so, because I tried with '127.0.0.1' and I got the same error).
> >And the big one, Why I get the error and how can I avoid it in future
> >applications?
>
> >Lot of thanks in advance!!
>
> You're seeing the expected behavior.  The example doesn't take care to
> handle any error conditions.  It has other bugs as well, such as not
> checking the return value of socket.send().
>
> Here's a different echo example:
>
>  http://twistedmatrix.com/projects/core/documentation/examples/#auto0
>
> Jean-Paul

I tried it in Linux and it worked fine so I've been trying different
things as the code seems to be correct.
Finally, I've found that if both server and client are run from IDLE,
the thing crashes with the mentioned error. But if the server is run
within a shell and the client within IDLE (or another shell) it works
perfectly. Therefore I suppose the problem is in IDLE (or in my actual
IDLE version) and not in the code.
Thanks for your answers Chris and Jean-Paul.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python and Test Driven Development

2006-05-19 Thread Diego Torres Milano

			First part of a series of articles about Python and Test Driven Development can be found at http://dtmilano.blogspot.com/2006/05/python-and-test-driven-development.html.


These articles include some scripts to ease automatic test suite creation in Python.


Comments are gladly welcome.
-- 
http://mail.python.org/mailman/listinfo/python-list

Binary Trees in Python

2005-08-20 Thread [diegueus9] Diego Andrés Sanabria
Hello!!!

I want know if python have binary trees and more?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TKinter in Python - advanced notions

2023-06-22 Thread Diego Souza via Python-list
Have you considered improving the architecture itself, not your GUI library
skills?

I recommend you look at the Model View ViewModel (MVVM) concept and
implement something similar (this is largely used in the Android framework
nowadays). This would separate your program logic from the rendering and
visualization. It would also make your program more reactive, decoupled,
and easier to maintain. When you mentioned threads I immediately thought of
this because it is much easier to implement parallel jobs and present
results back in the GUI, as everything becomes reactive. This is overkill
for a small project such as the code you showed, but I recommend it for
larger projects.





On Wed, Jun 21, 2023 at 7:20 PM aapost via Python-list <
python-list@python.org> wrote:

> On 6/21/23 09:47, Dan Kolis wrote:
> > I've write a huge biotech program ( an IDE for synthetic biology ), and
> am slowly outgrowing TKINTER.
> >
> > Has anybody out there merged a little bit of TCL direct calls from
> Python 3.X to get more freedom then TKINTER for just some Windows ?
>
> > I wish it looked better, but its 'ok'. I believe X11 IO is considerably
> superior for serious work the HTML.  I mean 'serious' work. with lots of
> multi media windows. I am not talking about fb "Oh ! There is a window it
> opened inthe corner !"... trivial functionality.
>
>
> I don't know if it would help, but you can extend/add tcl/tk packages
>
> I don't remember the full instructions right off, but quickly reverse
> engineering my old stuff I think you just need to drop them in
> /usr/share/tcltk/ or equivalent.
>
> (I needed to do that to replace the terrible looking default file dialog
> for unix/linux with fsdialog.)
>
> then running something like the following from your Tk object
>
> self.eval('package require fsdialog')
>
> (reverse engineering the python tkinter source you can likely find other
> ways of doing more tcl direct stuff)
>
> I have not researched if there are some better, more featured
> (non-buggy) Text widgets implemented in tcl that can be dropped in, (I
> know several of the tcl drop in widgets I tried were lacking in
> refinement).
>
>  From what I can tell, once upon a time there were better, more
> interesting projects and tutorials on extending tkinter, such as WCK
> (tkinter3000), but the only remnants of those remain publicly available
> are outdated unmaintained archives.
>
> You might also consider looking at the Grail browser source for research
> purposes, as it does some interesting things with some of the widgets,
> (parsing html and such), even though it is 20 years old now (and written
> in python 1).
> The update attempts from 10+ years ago have disappeared. (it's license
> is considered questionable from what I understand, so not sure if that
> is an aspect of it, the other being one of it's main features, python
> applets, is unsafe and was not easily fixable)
>
> You might already be beyond some of these things though.
>
> I know what you mean as far is feeling like the little bit extra you
> need pushes beyond what tkinter can do / makes you feel like you have
> outgrown the module.
>
> (I had to take a break from one of my projects and send it to
> development hell until my UI knowledge/skills improve after I found
> myself considering using xml schema appinfo annotations to store json
> formatted widget specific information, lol.)
>
> I have felt that sense of lack with most of the UI modules I have tried
> though.
>
> I don't know of a clear better python-only solution though that fits my
> personal needs.
>
> So I have to lean toward improving my tcl / C in hopes that it might
> help steer me toward that extra (which seems to be in the spirit of what
> tcl/tk's intent is to begin with). That will be a while for me though if
> I get there.
>
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>


-- 
Diego Souza
Wespa Intelligent Systems
Rio de Janeiro - Brasil
-- 
https://mail.python.org/mailman/listinfo/python-list