you need something more advanced
straight away, I'd say go for Cheetah.
In case you decide not to use a template engine at all, given that your
input format is XML, consider using lxml to build up your code tree for you
by using custom element classes. Then, generate the code recursively top-down
news on 2011/09/26, I'm not sure the project is still alive.
For FLOSS projects, it's usually better to look at the revision history,
which, in this case, names September 3 as last entry, *this* year.
Pretty much alive, I'd say.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
section and section
> from my xml, (because it has the word NC) but need to keep
>
> can someone point me to the correct direction, or code snippet
Use the xml.etree.ElementTree module. Just parse() in the file, iterate
over the nodes, use the findtext() method to search for
).
http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html
I agree with discouraging 1) in specific.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
is quite irrelevant once it has been running for a while.
The distinction between embedding and extending, as the Python docs put it,
is actually quite fuzzy when it comes to the actual code interaction.
Note also that this isn't the use case here, the OP asked for wrapping a
C++ type for use in P
m/CCC/2011/06/13/CC}Rating";):
>x = child.find('Rating').text
> if child[1].text == 'NC':
> print "found"
>root.remove('TVEpisode') ?
> tree.write('output.xml')
The trick is to search for the parent node, then let your code find out if
you need to remove it or not by traversing its subtree.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
maps each Element to its parent
by traversing the tree once.
Alternatively, use lxml.etree, in which Elements have a getparent() method
and in which single parents are enforced (also by design).
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
try:
read = file_or_string.read
except AttributeError:
data = file_or_string
else:
data = read()
I'd rather go with one of the previous solutions, though.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
e object you pass in using the "latin-1" encoding. Since a list is
not something that is "encoded", let alone in latin-1, you get an error,
and actually a rather clear one.
Note that this is not specific to Python3.3 or even 3.x. It's the same
thing in Py2 when you call the
ts that need more than just a
call to str(), some kind of further preprocessing?
There are so many ways to do something like this, and it's so straight
forward to do in a given use case, that it's IMHO useless to even think
about adding a "general solution" for this to the stdlib.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
r lxml rather than the plain
libxml2/libxslt Python bindings and seeing that you don't fear installing
software from arbitrary web pages, you should try this binary installer:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
earch, page_nums)
> valid_pages = itertools.takewhile(bool, pages)
> tweets = itertools.chain.from_iterable(valid_pages)
> return tweets
I'd prefer the original code ten times over this inaccessible beast.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
r description text should be in a CDATA section.
> http://en.wikipedia.org/wiki/CDATA#CDATA_sections_in_XML
Ah, don't bother with CDATA. Just make sure the data gets properly escaped,
any XML serialiser will do that for you. Just generate the XML using
ElementTree and you'll be fine. Generating XML as literal text is not a
good idea.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
pyvideo.org/video/1443/erfahrungen-mit-py4a-sowohl-mit-sl4a-als-auch
He's using it for teaching purposes.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
ot;Total Assets" part.
>
> This should work:
>
> list_row2 = doc2.xpath(u'.//td[strong[contains(text(),"Total
> Assets")]]/following-sibling::td/strong/text()')
Something like "contains(text(),"Total Assets")" is better expressed as
"contains(.,"Total Assets")" because it considers the complete text content
instead of just one text node.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
# or whatever you use
However, how you'd use it depends on your actual C code. Personally, I'd
drop C and write all Python interaction in Cython. Makes these things way
easier.
Here are some longer examples:
https://github.com/cython/cython/tree/master/Demos/embed
https://github.com/cython/cython/tree/master/Demos/callback
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
ou to do and to try out.
So you get more by investing less. Not the worst choice IMHO.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
; XML with the escaping isn't valid XML.
>
> Of course I know it is not valid without escaping. But I need it only for
> signing. I will recheck this if really the web service wants the data to be
> signed as non escaped.
If it expects non-XML, you should tell the owners of the
d, since ß does not occur at the beginning
of a word. As far as I know, most Germans wouldn't even know that it has
existed at some point or how to write it.
Stefan Krah
--
http://mail.python.org/mailman/listinfo/python-list
or a
> programer who wants to develop a web application and doesn't know Javascript.
> Ultimately this means that the whole DOM API would be described without any
> mention of Javascript, only with the Python API
If that's your intention, then instead of coming up with something totally
new, unpythonic and ugly, why not take the normal Python route and
implement a subset of the ElementTree API?
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
html.builder import *
> >>> snippet = DIV("Hello ", B("world"))
> >>> etree.tostring(snippet)
> 'Hello world'
For which there even happens to be an ElementTree implementation available:
http://svn.effbot.org/public/stuff/sandbox/elementlib/builder.py
(It's not like I made this up ...)
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
n concerns - it looks like useless code, which is
totally different from what it does. So it basically uses magic
side-effects as part of the design, which is never a good thing.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
3:16)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def f(*args): print(args)
>>> f(34, ..., 43)
(34, Ellipsis, 43)
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
s in with the PGO build in 3.3.
Stefan Krah
--
http://mail.python.org/mailman/listinfo/python-list
O builds
> or not.
I remember that some versions of Visual Studio silently completed the PGO build
without actually having PGO capabilities. :)
I think for VS 2008 at least "Professional" is needed, for VS 2010 "Ultimate".
Stefan Krah
--
http://mail.python.org/mailman/listinfo/python-list
ne version behind the latest.
I wouldn't attempt it. For Python 3.3 the conversion has been done and the diff
was enormous.
Stefan Krah
--
http://mail.python.org/mailman/listinfo/python-list
ou don't normally care about
the votes but read the comments frequently. It's just a matter of adding an
indirection for things that you use less frequently and/or that you use in
more than one place (not in your case, where comments and votes are unique
to an article).
You see, lots of options, even just using the stdlib...
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
e with any proprietary software that you link
against GPL code. As long as you don't ship your code to someone else who
doesn't have access to your source code, you're free to do whatever you
like with it. That's usually the case when you deploy your software on your
own servers, for example. Only if you distribute your software to other
people, the GPL enforces that you give them your source code under the same
license.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
e things in plain C. If nothing else, it saves you from
having to put thoughts into reference counting and other common CPython
C-API pitfalls.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
re are several ways to do it. Python has a couple of external libraries
available that are made specifically for generating markup incrementally.
lxml also gained that feature recently. It's not documented yet, but here
are usage examples:
https://github.com/lxml/lxml/blob/master/src/lxml/tests/test_incremental_xmlfile.py
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
ented a web interface for the simulator that monitored
and visualised its current state. They said it helped them with debugging.
> What language was the web page hosted in? It comes up completely blank
> for me. :)
Yep, same here. Hidden behind a flash wall, it seems.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
on?
> I mean just the code not compiled ?
Not sure what you mean. Are you maybe looking for an open-source project?
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
tainly keep an
attacker from having to figure out hash collisions in order to bring down a
system. Sending *any* arbitrarily varied data would be enough then.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
n you're not using lxml?
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
that the C code that it generates from your Python code will be more
efficient than what you'd write manually. Certainly more readable and
maintainable.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
but am wondering what the most
> normal pronunciation is. And am fully prepared for the possibility
> that there is no one "most normal"!
I think a more obvious way to call it would be "cheeseshop", but since that
was tried and rejected, I'm all for making it "Pippi" officially.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
y_print=True,
>encoding=out_encoding)
>with open(filename,'wb') as f:
>f.write(result)
Use tree.write(f, ...)
Assuming you really meant XHTML and not HTML, I'd just drop your entire
code and do this instead:
tree = etree.parse(in_path)
tree.write(out_path, encoding='utf8', pretty_print=True)
Note that I didn't provide an input encoding. XML is safe in that regard.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
'it = iter(l); next(it); all(it)'
1000 loops, best of 3: 935 usec per loop
python3.3 -m timeit -s 'l=list(range(10))' \
-s 'from itertools import islice' \
'all(islice(l, 1, None))'
1000 loops, best of 3: 1.63 msec per loop
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
Tim Arnold, 01.02.2012 19:15:
> On 2/1/2012 3:26 AM, Stefan Behnel wrote:
>> Tim Arnold, 31.01.2012 19:09:
>>> I have to follow a specification for producing xhtml files.
>>> The original files are in cp1252 encoding and I must reencode them to
>>> utf-8.
Hi,
I'm pleased to announce the release of cdecimal-2.3. cdecimal is a fast
drop-in replacement for the decimal module in Python's standard library.
Blurb
=
cdecimal is a complete implementation of IBM's General Decimal Arithmetic
Specification. With the appropriate context parameters, cdec
For C, I think the why3 tool should be a good approach:
http://why3.lri.fr/
The verification of the L4 kernel allegedly took 30 man-years, so
it might take a while...
Stefan Krah
--
http://mail.python.org/mailman/listinfo/python-list
x.html
Not sure which went first, but since you mentioned that you're "releasing
soon", you may want to stop the engines for a moment and reconsider the name.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
computation
d) testing (non-Python/embedded/whatever code)
I'm sure others will manage to remind me of the one or two I forgot...
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
d differences (currently I am using xsltproc)? Any
> thoughts?
You could try switching to lxml. It would at least allow you to do a part
of the processing in Python and only use XSLT when it seems more
appropriate and/or easier.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
hat would be an
> implementation detail in any case.
Absolutely.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
Stodge, 17.02.2012 02:15:
> Does anyone know of a library to generate class definitions in memory,
> at runtime, from XSD or JSON?
The question is: why do you want to do that? There may be other ways to do
what you *actually* want to do, but we don't know what that is.
Stefa
The XSLT language is one of the worst misuses of XML, which puts it way
> beyond bad.
Clearly a matter of opinion.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
layouting programs from MS-Office fame, but at
least older versions of many a program tend to work rather nicely.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
, [])
> [1, 2, 3, 4]
I know that you just meant this as an example, but it's worth mentioning in
this context that it's not exactly efficient to "sum up" lists this way
because there is a lot of copying involved. Each adding of two lists
creates a third one and copies all elements into it. So it eats a lot of
time and space.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
unction, I think.
> Do I really switch to setuptools?
No, use "distribute" instead.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
en PyXML?
PyXML was meant as an extension and hooked into the stdlib XML support.
That's only one of the reasons why it's broken now.
> Anyway, python's xml is newer - is PyXML deprecated?
Yes. It's a dead project.
> Please keep me in CC, I'm not subscribed to the list.
That may be the problem in the xml-sig case also.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
t you just
install Linux on it?
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
y best
to start with Cython right away, instead of using ctypes.
http://cython.org/
Here's a tutorial for wrapping a C library with it:
http://docs.cython.org/src/tutorial/clibraries.html
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
g it in a class.
>
> You should get acquainted with the Python/C API
If it proves necessary, yes.
> which is the standard way of extending Python with high-performance
> (and/or system-specific) C code.
Well, it's *one* way. Certainly not the easiest way, neither the most
portable and y
eplace(CYTHONCFILESUFFIX='.cpp')
I don't use Scons, so I don't know if running the compiler at a command
line level is the best way to do it in that build system. But I know that
some people on the Cython users mailing list use it, so you may want to ask
over there.
https://groups.google.com/group/cython-users
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
Hrvoje Niksic, 11.03.2012 02:03:
> Stefan Behnel writes:
>>> which is the standard way of extending Python with high-performance
>>> (and/or system-specific) C code.
>>
>> Well, it's *one* way. Certainly not the easiest way, neither the most
>> portab
dated. I'm looking at converting to
> html5lib.)
You may also consider moving to lxml. BeautifulSoup supports it as a parser
backend these days, so you wouldn't even have to rewrite your code to use
it. And performance-wise, well ...
http://blog.ianbicking.org/2008/03/30/python-html-parser-performance/
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
nce instead. For user provided exceptions, there
is no real excuse for raising the type.
BTW, StopIteration takes an optional argument in Python 3.3, but that's not
a feature that is generally going to be used by Python code, I assume. So
I'll just keep raising the type. :)
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
Steven D'Aprano, 12.03.2012 16:08:
> On Mon, 12 Mar 2012 14:52:49 +0100, Stefan Behnel wrote:
>>> "raise X" is a special case of the 3-args raise. Effectively it just
>>> raises an instance of X which is constructed with an empty argument
>>> list. Ther
t; new_demo_obj = my_C_extension.function_2()
You should consider giving Cython a try. It will allow you to write normal
Python code for your C extension that it translates to efficient C code.
This is much easier than writing all of this by hand, especially when it
comes to classes. It
rowd, so to me this sounds as overkill
Well, there's databases and databases. I agree that the complexity of a SQL
database is likely unnecessary here since a key-value database (any of the
dbm modules) appears to be sufficient from what the OP wrote.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
head that cygwin induces into a lot of common OS operations (such as
fork(), I/O operations or file system access), a native Windows Python
installation has serious advantages in most cases.
If the choice is GCC, then MinGW is the right tool.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
code is produced
>>
>> Or you could be asking about Python version 3, in which case
>> 1) the syntax error message points to a different character
>
> Oh ,God !
I don't think she takes any responsibility for the list above.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
ode "better" in some
way, e.g. by making it more readable or easier to extend. Obfuscation aims
for making it worse, as in unreadable and hard to access. It's generally
not a good idea to do that. Code is there for humans to read.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
, we may be able to tell you how to do what you want.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
ere does the data come from and
why is it contained in a character string in the first place? If you could
provide that information, we can help you further.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
ndex;
> }
It would have been nice if you had added some explanatory text to this code
dump.
What do you mean by "resolve"?
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
ost likely understand what
I'm talking about by reading the code. :-)
http://sschwarzer.com/download/robustere_python_programme_clt2010_print.pdf
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
/wiki/Future_%28programming%29
[3] http://www.python.org/dev/peps/pep-3148/
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
ut in my reader I
only saw one answer in the newsgroup.)
Stefan Schwarzer wrote:
> I wrote a `Connection` class that can be found at [1]. A
> `Connection` object has a method `put_bytes(data)` which
> returns a "future" [2]. The data will be sent asynchronously
> by a thread
uot; are and what kind of application we are talking
about (graphic, headless server, ...).
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
tial/Stanford_Parser
It usually helps to report what exactly you tried and what the result was.
Did the installation work at all? How did you install it? What did you try
afterwards? What failed? What documentation did you read so far?
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
t http://python.org
Also note that there is a separate mailing list (the tutor list)
specifically targeted at new Python users:
http://mail.python.org/mailman/listinfo/tutor
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
Peter Faulks, 26.04.2012 21:28:
> "All you have to do is assign to print". Sounds great! Can some kind soul
> hit me with a clue stick? Were do I look in the API?
Here's the (Py3) Cython code for it:
print = my_print_function
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
>
> printoverload.set_stdout()
> printoverload.set_stderr()
>
> print("this will be sent to a C function in printoverload.pyd")
> ---
Why would you want to divert only "print" instead of changing sys.stdout in
general? Not all output comes fro
Peter Faulks, 27.04.2012 10:36:
> On 27/04/2012 5:15 PM, Stefan Behnel wrote:
>> Peter Faulks, 26.04.2012 19:57:
>>> I want to extend an embedded interpreter so that calls to print() are
>>> automagically sent to a C++ gui (windows exe) via a callback function in
>&g
Peter Faulks, 27.04.2012 22:31:
> On 27/04/2012 6:55 PM, Stefan Behnel wrote:
>> Peter Faulks, 27.04.2012 10:36:
>>> On 27/04/2012 5:15 PM, Stefan Behnel wrote:
>>>> Peter Faulks, 26.04.2012 19:57:
>>>>> I want to extend an embedded interpreter so that
Ian Kelly, 04.05.2012 01:02:
> BeautifulSoup is supposed to parse like a browser would
Not at all, that would be html5lib.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
if you really wanted to do this particular thing, I'd just use heapq.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
, 'wb') as p:
>> for i, j in temp:
>>p.write('%s %s\n' %(str(i),j))
How much memory do you have on your system? Does the list fit into memory
easily or is it swapping to disk while you are running the sort?
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
f HTML mails.
Your problem description was very good, BTW. It included the perfect amount
of information about what you tried and what didn't work for you about it.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
ten faster than hand written C
code).
http://cython.org/
Here are a couple of examples:
http://docs.cython.org/src/tutorial/external.html
There's also the "ctypes" package in the standard library, which is usable
for simple wrapping cases that are not performance critical.
O is much better spent adding features
and tuning the code for performance.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
Mark Lawrence, 13.05.2012 19:27:
> On 13/05/2012 16:58, Stefan Behnel wrote:
>> David Shi, 13.05.2012 15:25:
>>> Can anyone tell me how to call and exectute C code in Python?
>>
>> Take a look at Cython, a Python-like language that supports native calls to
>>
Mark Lawrence, 13.05.2012 19:44:
> On 13/05/2012 18:38, Stefan Behnel wrote:
>> Mark Lawrence, 13.05.2012 19:23:
>>> On 13/05/2012 16:39, Chris Angelico wrote:
>>>> On Sun, May 13, 2012 at 11:25 PM, David Shi wrote:
>>>>> Can anyone tell
re discussing at *that* level.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
them, and they got it pretty
much right (didn't try the others).
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
as ET # using fast C accelerator module
root = ET.parse("afile.xml").getroot()
for child in root:
if child.tag == 'abc':
print("abc tag found")
else:
print("other tag found")
There's also an incremental i
en you can just get your code working without having to learn all of this
again?
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
> install them all again somehow...
You should install "distribute" and "pip" into it, then you can use pip to
install packages directly and automatically from the Python Package Index
(PyPI), including any dependencies.
Even better, use "virtualenv" to create a local
s some untested code to print the text values:
import xml.etree.ElementTree as ET
loadavg = ET.fromstring('0.000.00'
'0.00')
for interval_tag in ('one', 'five', 'fifteen'):
print(loadavg.findtext(interval_tag))
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
Hi,
please don't top-post (I fixed the citation order below).
Nibin V M, 16.05.2012 16:30:
> On Wed, May 16, 2012 at 7:53 PM, Stefan Behnel wrote:
>> Nibin V M, 16.05.2012 16:16:
>>> I am trying to use cPanel XML-API and every API call return data in XML
>>> for
usually helps to provide a pointer to that "not updated text", so that
readers know what you are talking about and can more easily provide an
alternative.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
ollect all Java code that Jython executes
during the run of a Python program, you get pure Java code that is
equivalent to the Python program. Maybe not beautiful code, but definitely
Java code.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
David Shi, 04.06.2012 17:35:
> Compiling your Python code with jythonc
> I do not know whether I downloaded a wrong version of Jythonc? Or, got
> mismatched software or instructions.
Jythonc used to work in Jython 2.2 but is no longer supported in Jyton 2.5.
Stefan
--
http://mail.p
andrea crotti, 13.06.2012 12:06:
> Hello Python friends, I have to validate some xml files against some xsd
> schema files, but I can't use any cool library as libxml unfortunately.
Any reason for that? Because the canonical answer to your question would be
lxml, which uses libxm
rt of translate to "of the" and for a book spine "of the XYZ"
> may be meaningless unless the given name is included, a la "ABC of the
> XYZ"...
It's a bit like using "New York" as a surname, when you refer to that guy
Jason who was born there, as in "Jason of New York".
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
though -
which ones should be executed if the package structure is multiplied?
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
Add two numbers.
>>> 1+1
2
>>> add(1,1)
2
>>> add(1,1) == 1+1
True
"""
return x+y
http://docs.python.org/library/doctest.html
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
Or
is this approach a stupid idea to begin with? Pointers would be highly
appreciated.
Spot the pun. ;)
Take a look at PyCapsule, it may (or may not) be enough for your use case.
However, note the comment about Py_InitModule4() in the docs, where it says
that the 'self' passing fe
101 - 200 of 2239 matches
Mail list logo