os.rename() problems on OS X
hello, i recently had the job of having to rename about 200 files. The source for the renaming was a bunch of names in a file. I know next to nothing when it comes to bash scripting (which would have seemed the obvious choice) so i used python. The files i was renaming were canon raw files (.CR2). my problem is that after i rename the files, OS X will no longer render the thumbnails for the files, and preview is no longer the default app for viewing them. Does anyone have an idea as to why this is? Thanks for the help :) -Lukas -- http://mail.python.org/mailman/listinfo/python-list
Re: xlrd 0.7.4 released!
Hey Chris, On Tuesday, April 3, 2012 9:04:43 AM UTC+2, Chris Withers wrote: > > Hi All, > > I'm pleased to announce the release of xlrd 0.7.4. > There seems to have been a mistake during release of 0.7.4: version.txt referenced in setup.py:24 is missing (forgot MANIFEST?) and therefore the package can't be installed. Getting distribution for 'xlrd'. error: /var/folders/_l/m3y541vx5m1dzgjm6rjljf5wgn/T/easy_install-KeGyEg/xlrd-0.7.4/xlrd/version.txt: No such file or directory An error occured when trying to install xlrd 0.7.4. Look above this message for any errors that were output by easy_install. Regards, Lukas -- http://mail.python.org/mailman/listinfo/python-list
Re: [pyxl] xlrd 0.7.4 released!
On Tuesday, April 3, 2012 9:34:27 AM UTC+2, Chris Withers wrote: > As pointed out, I stuffed up the release by not including a new file in > the MANIFEST. My bad. > > I've just release a 0.7.5 that fixes this. > Works! Thanks for the quick reaction! Regards, Lukas -- http://mail.python.org/mailman/listinfo/python-list
annotations cause dataclass fields type side effects
I'm on Python 3.9.6 and trying to make sense of the following behaviour: >>> from dataclasses import dataclass, fields >>> @dataclass ... class Foobar: ... name: str ... >>> fields(Foobar)[0].type >>> type(fields(Foobar)[0].type) >>> from __future__ import annotations >>> from dataclasses import dataclass, fields >>> >>> @dataclass ... class Foobar: ... name: str ... >>> fields(Foobar)[0].type 'str' >>> type(fields(Foobar)[0].type) I have a validation function that checks if the types of all fields in a dataclass are what they are supposed to be. But as soon as I import annotations from __future__ this validation breaks as the arg that I'm passing to isinstance() is no longer a type class but a string. What am I doing wrong? Thanks, -- Lukas -- https://mail.python.org/mailman/listinfo/python-list
Most pythonic way of rotating a circular list to a canonical point
Hi! I have a list of numbers that I treat as "circular", i.e. [1,2,3] and [2,3,1] should be the same. Now I want to rotate these to a well defined status, so that I can can compare them. If all elements are unique, the solution is easy: find the minimum element, find its index, then use mylist[:index] + mylist[index:], i.e. the minimum element will always be at the beginning. But say I have [0,1,0,2,0,3]. I can in fact guarantee that no *pair* will appear twice in that list, i.e. I could search for the minimum, if that is unique go on as above, otherwise find *all* positions of the minimum, see which is followed by the smallest element, and then rotate that position to the front. Now that seems an awful lot of code for a (seemingly?) simple problem. Is there a nice, pythonic way to do this? Thanks for enlightening me! Lukas -- https://mail.python.org/mailman/listinfo/python-list
Re: Most pythonic way of rotating a circular list to a canonical point
On Saturday, August 1, 2015 at 10:57:19 PM UTC+2, Marko Rauhamaa wrote: > > def circularly_equal(l1, l2): > length = len(l1) > if length != len(l2): > return False > twice = l1 + l1 > for i in range(length): > if twice[i:i + length] == l2: > return True > return False > Nice idea! But I actually really need those "canonic rotations", since I'm hashing them somewhere.. Lukas -- https://mail.python.org/mailman/listinfo/python-list
Re: Most pythonic way of rotating a circular list to a canonical point
On Saturday, August 1, 2015 at 10:51:03 PM UTC+2, Emile van Sebille wrote: > Is the problem to determine if one list of circular numbers 'matches' > another one despite rotation status? If so, I'd do something like: Well.. no. I actually really need this "canonical" rotation, since I'm hashing this, returning it to other parts of the software, etc.. But thanks! Lukas -- https://mail.python.org/mailman/listinfo/python-list
Re: Most pythonic way of rotating a circular list to a canonical point
Perhaps I should clarify a bit: - I definitely need a "canonical rotation" - just a comparison result is not enough - It does not matter what that rotation is. Starting with the smallest element was just an idea by me, any rotation that can easily produced will do. -- https://mail.python.org/mailman/listinfo/python-list
Re: Most pythonic way of rotating a circular list to a canonical point
On Saturday, August 1, 2015 at 11:37:48 PM UTC+2, Emile van Sebille wrote: > Well, it looks to me that I don't know what a 'canonical rotation' is -- That's because it is not defined. ;) I need a way to rotate one of these lists in a way so that it will produce the same output every time, regardless of what the input rotation was. Example: [0,1,2,3,4] => [0,1,2,3,4] [2,3,4,0,1] => [0,1,2,3,4] [3,4,0,1,2] => [0,1,2,3,4] ... It doesn't have to be "[0,1,2,3,4]", it can just as well be [2,3,4,1,0], as long as it's always the same. Did that make it clearer? Thanks a lot, Lukas -- https://mail.python.org/mailman/listinfo/python-list
Re: Most pythonic way of rotating a circular list to a canonical point
On Saturday, August 1, 2015 at 11:43:28 PM UTC+2, Paul Rubin wrote: > How large are these lists supposed to be? Potentially large. Not so large though that iterating them (multiple times) should be a problem. > [Concatenated Hashes] > > If the lists are very large that doesn't sound so great due to storage > requirements.. Also, that still doesn't compute that one "canonical ordering"... Thanks, Lukas -- https://mail.python.org/mailman/listinfo/python-list
Re: Most pythonic way of rotating a circular list to a canonical point
On Sunday, August 2, 2015 at 12:32:25 AM UTC+2, Cameron Simpson wrote: > Fine. This also eliminates any solution which just computes a hash. Exactly. > Might I suggest instead simply starting with the leftmost element in the > first > list; call this elem0. Then walk the second list from 0 to len(list2). If > that > element equals elem0, _then_ compare the list at that point as you suggested. > > Is there an aspect of this which doesn't work? The problem is: When I compute a hash over list1 (in its canonical form), I do not yet know list2 (or list3, or listN...) against which they will be compared later.. Lukas -- https://mail.python.org/mailman/listinfo/python-list
Re: Most pythonic way of rotating a circular list to a canonical point
On Sunday, August 2, 2015 at 1:05:32 AM UTC+2, Oscar Benjamin wrote: > Do you really need the canonical rotation or just a hash that is invariant > under rotations? Having that canonical rotation would make the code simpler and faster, probably, but a rotationally invariant hash is a good start. > I don't know of a solution to the former that is better than what you already > have but the latter is an easier problem: Find the minimum element. Compute > the hash of the rotated sequence for each occurrence of the least common > element. Add those hashes together or multiply them or some similar > operation. That's your hash that will compare equal for any rotation of a > given sequence. Yes, that sounds like an idea if I decide to just go with the hash. Thanks! Lukas -- https://mail.python.org/mailman/listinfo/python-list
Detect File System changes
Hello, I'm trying to detect changes in a directory. E.g if someone crates a file, i'll execute another function on this file. I tried to solve this by creating a loop that permanently checks the contents of this directory with os.listdir() and compares it with the one before. But this isn't really working properly. Can anyone give me a hint to get this working? best regards, Lukas -- http://mail.python.org/mailman/listinfo/python-list
Re: Detect File System changes
Hello, Thank you for your assistance. I could manage it using your link to the already discussed thread. best regards, Lukas -- http://mail.python.org/mailman/listinfo/python-list
cx_oracle
Hi,
I want to get an access to an oracle database.
For that I found the module cx_oracle
(http://www.python.net/crew/atuining/cx_Oracle/) and
I have installed the version 'Windows Installer (Oracle 10g, Python 2.5)'.
Now I tried to run the script in the readme file:
---
import cx_Oracle
# connect via SQL*Net string or by each segment in a separate argument
#connection = cx_Oracle.connect("user/[EMAIL PROTECTED]")
connection = cx_Oracle.connect("user", "password", "TNS")
cursor = connection.cursor()
cursor.arraysize = 50
cursor.execute("""
select Col1, Col2, Col3
from SomeTable
where Col4 = :arg_1
and Col5 between :arg_2 and :arg_3""",
arg_1 = "VALUE",
arg_2 = 5,
arg_3 = 15)
for column_1, column_2, column_3 in cursor.fetchall():
print "Values:", column_1, column_2, column_3
---
And I got an error:
---
Traceback (most recent call last):
File "C:\Python25\cal_adjustment.py", line 1, in
import cx_Oracle
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.
---
Do someone have an idea to solve the problem? A reinstall doesn't work.
Cheers
lukas
--
http://mail.python.org/mailman/listinfo/python-list
logging.Handler not working with QThreads
Hello,
I created a QTextEdit where I wanted to display log messages.
A logging.Handler should do this job.
It worked with one thread well, but when I start a QThread the text on all
widgets is removed and I get many errors in my konsole:
X Error: RenderBadGlyphSet (invalid GlyphSet parameter) 177
Extension:152 (RENDER)
Minor opcode: 25 (RenderCompositeGlyphs32)
Resource id: 0x0
X Error: RenderBadGlyphSet (invalid GlyphSet parameter) 177
Extension:152 (RENDER)
Minor opcode: 25 (RenderCompositeGlyphs32)
Resource id: 0x0
X Error: RenderBadGlyphSet (invalid GlyphSet parameter) 177
Extension:152 (RENDER)
Minor opcode: 25 (RenderCompositeGlyphs32)
Resource id: 0x0
.. and so on
I attatched a small example to this mail.
Could anybody tell me what I'm doing wrong?
Thanks for you help,
Lukas
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import logging
class QtStreamHandler(logging.Handler):
def __init__(self, parent, main):
logging.Handler.__init__(self)
self.parent = parent
self.main = main
self.textWidget = parent
self.formater = logging.Formatter("%(message)s")
def createLock(self):
self.mutex = QMutex()
def acquire(self):
self.mutex.lock()
def release(self):
self.mutex.unlock()
def emit(self,record):
self.textWidget.appendPlainText(self.formater.format(record))
self.textWidget.moveCursor(QTextCursor.StartOfLine)
self.textWidget.ensureCursorVisible()
class Log(QDialog):
def __init__(self, parent, main):
super(Log, self).__init__(parent)
self.parent = parent
self.main = main
self.layout = QVBoxLayout(self)
self.logEdit = QPlainTextEdit(self)
self.logEdit.setLineWrapMode(QPlainTextEdit.NoWrap)
self.logEdit.setReadOnly(True)
self.button = QPushButton(self)
self.button.setText("Message")
self.layout.addWidget(self.logEdit)
self.layout.addWidget(self.button)
self.connect(self.button, SIGNAL("clicked()"), self.message)
self.show()
def message(self):
self.main.log.error("Log window")
class MainWindow(QDialog):
def __init__(self, parent, main):
super(MainWindow, self).__init__()
self.parent = parent
self.main = main
self.layout = QVBoxLayout(self)
self.check = QCheckBox(self)
self.check.setText("Foobar")
self.combo = QComboBox(self)
self.combo.addItem("")
self.combo.addItem("")
self.button = QPushButton(self)
self.button.setText("Start Thread")
self.button2 = QPushButton(self)
self.button2.setText("Message")
self.layout.addWidget(self.check)
self.layout.addWidget(self.combo)
self.layout.addWidget(self.button)
self.layout.addWidget(self.button2)
self.connect(self.button, SIGNAL("clicked()"), self.startThread)
self.connect(self.button2, SIGNAL("clicked()"), self.message)
self.show()
def startThread(self):
self.thread = Thread(self, self.main)
self.connect(self.thread, SIGNAL("finished()"), lambda : self.main.log.error("Thread finished"))
self.thread.start()
def message(self):
self.main.log.error("Main window")
class Thread(QThread):
def __init__(self, parent, main):
super(Thread, self).__init__(parent)
self.log = main.log
def run(self):
self.log.info("Thread...")
class Main(QObject):
def __init__(self):
super(Main, self).__init__()
logger = logging.getLogger("series60-remote")
logger.setLevel(logging.DEBUG)
self.logWindow = Log(None, self)
dialogHandler = QtStreamHandler(self.logWindow.logEdit, self)
logger.addHandler(dialogHandler)
self.logWindow.show()
self.log = logger
self.window = MainWindow(None, self)
app = QApplication([])
main = Main()
app.exec_()
--
http://mail.python.org/mailman/listinfo/python-list
