pypi mirror

2011-05-19 Thread Slafs
Hi there.

I would like to make a "local" mirror of some packages that are on
pypi. What options do You recommend ?

I am leaning towards z3c.pypimirror because it was kind of first on my
google search results.

Regards

Sławek
-- 
http://mail.python.org/mailman/listinfo/python-list


cx Oracle privileges

2009-02-19 Thread Slafs
Hello

On my Debian server I'm using cx Oracle 5.1 (installation from a
package made from rpm by alien) with Python 2.5.2
and Oracle Instant Client 10.2.0.4.0. Installation went well but
simple test such as connecting to the db shows that only user root can
make a connection to a database, but any other user can't do this
becuse
>>> import cx_Oracle
>>> connection = cx_Oracle.Connection('user/[email protected]/dbsid')
hangs :/

I've checked privileges to instant client and cx_Oracle.so in site-
packages and they are fine.

Did anyone came across with similar problem or maybe can show me where
I should look for the cause?

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


yacc statement recognition

2009-01-01 Thread Slafs
Hi ALL!

I have to write in yacc an acceptor of files with lines matching this
regexp:
'[0-9],[0-9]'
and I don't know what I am doing wrong beacuse this:


tokens = (
   'NUMBER',
)
literals = [',']

t_NUMBER = r'\d'

...

def p_statement_exp(p):
'''statement :  NUMBER ',' NUMBER
'''
print "OK!"
sys.exit()
---

also accepts lines like 2,abcdef3 which of
could someone please tell me what's wrong in my code?

full source on http://paste-it.net/public/vba22d5/
--
http://mail.python.org/mailman/listinfo/python-list


XML root node attributes

2009-11-17 Thread Slafs
Hi

I'm little confused about adding attributes to the root node when
creating an XML document.
Can I do this using minidom or something else.
I can't find anything that would fit my needs.

i would like to have something like this:


 
   


Please help.

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


Re: XML root node attributes

2009-11-18 Thread Slafs
Thanks

But this doesn't work. I've ended using something like this:

import xml.etree.ElementTree as ET
root = ET.Element("root", dict(a='v', b='v2', c='v3'))
n = ET.SubElement(root,'d')
tree = ET.ElementTree(root)
import sys
tree.write(sys.stdout)


On 17 Lis, 15:36, Stefan Behnel  wrote:
> Slafs, 17.11.2009 15:19:
>
> > I'm little confused about adding attributes to the root node when
> > creating an XML document.
> > Can I do this using minidom or something else.
>
> Yes, you /can/, but you /should/ use something else.
>
> > I can't find anything that would fit my needs.
>
> > i would like to have something like this:
> > 
> > 
> >      
> >    
> > 
>
> Use ElementTree:
>
>     import xml.etree.ElementTree as ET
>     root = ET.Element("root", dict(a='v', b='v2', c='v3'))
>     root.SubElement('d')
>
>     print ET.tostring(root)
>
> Stefan

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


itertools.groupby usage to get structured data

2011-02-04 Thread Slafs
Hi there!

I'm having trouble to wrap my brain around this kind of problem:

What I have :
  1) list of dicts
  2) list of keys that i would like to be my grouping arguments of
elements from 1)
  3) list of keys that i would like do "aggregation" on the elements
of 1) with some function e.g. sum

For instance i got:
1) [ { 'g1' : 1, 'g2' : 8, 's_v1' : 5.0, 's_v2' : 3.5 },
  { 'g1' : 1, 'g2' : 9, 's_v1' : 2.0, 's_v2' : 3.0 },
  {'g1' : 2, 'g2' : 8, 's_v1' : 6.0, 's_v2' : 8.0}, ... ]
2) ['g1', 'g2']
3) ['s_v1', 's_v2']

To be precise 1) is a result of a values_list method from a QuerySet
in Django; 2) is the arguments for that method; 3) those are the
annotation keys. so 1) is a result of:
   qs.values_list('g1', 'g2').annotate(s_v1=Sum('v1'), s_v2=Sum('v2'))

What i want to have is:
a "big" nested dictionary with 'g1' values as 1st level keys and a
dictionary of aggregates and "subgroups" in it.

In my example it would be something like this:
{
  1 : {
  's_v1' : 7.0,
  's_v2' : 6.5,
  'g2' :{
   8 : {
  's_v1' : 5.0,
  's_v2' : 3.5 },
   9 :  {
  's_v1' : 2.0,
  's_v2' : 3.0 }
}
   },
  2 : {
   's_v1' : 6.0,
   's_v2' : 8.0,
   'g2' : {
8 : {
  's_v1' : 6.0,
  's_v2' : 8.0}
   }
   },
...
}

# notice the summed values of s_v1 and s_v2 when g1 == 1

I was looking for a solution that would let me do that kind of
grouping with variable lists of 2) and 3) i.e. having also 'g3' as
grouping element so the 'g2' dicts could also have their own
"subgroup" and be even more nested then.
I was trying something with itertools.groupby and updating nested
dicts, but as i was writing the code it started to feel too verbose to
me :/

Do You have any hints maybe? because i'm kind of stucked :/

Regards

Sławek
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: itertools.groupby usage to get structured data

2011-02-05 Thread Slafs
On 5 Lut, 05:58, Paul Rubin  wrote:
> Slafs  writes:
> > What i want to have is:
> > a "big" nested dictionary with 'g1' values as 1st level keys and a
> > dictionary of aggregates and "subgroups" in it
>
> > I was looking for a solution that would let me do that kind of
> > grouping with variable lists of 2) and 3) i.e. having also 'g3' as
> > grouping element so the 'g2' dicts could also have their own
> > "subgroup" and be even more nested then.
> > I was trying something with itertools.groupby and updating nested
> > dicts, but as i was writing the code it started to feel too verbose to
> > me :/
>
> > Do You have any hints maybe? because i'm kind of stucked :/
>
> I'm not sure I understood the problem and it would help if you gave
> sample data with the deeper nesting that you describe.  But the
> following messy code matches the sample that you did give:
>
>     from pprint import pprint
>     from itertools import groupby
>
>     x1 = [ { 'g1' : 1, 'g2' : 8, 's_v1' : 5.0, 's_v2' : 3.5 },
>               { 'g1' : 1, 'g2' : 9, 's_v1' : 2.0, 's_v2' : 3.0 },
>               { 'g1' : 2, 'g2' : 8, 's_v1' : 6.0, 's_v2' : 8.0}
>               ]
>     x2 = ['g1', 'g2']
>     x3 = ['s_v1', 's_v2']
>
>     def agg(xdata, group_keys, agg_keys):
>         if not group_keys:
>             return {}
>         k0, ks = group_keys[0], group_keys[1:]
>         r = {}
>         def gk(d): return d[k0]
>         for k, g in groupby(sorted(xdata, key=gk), gk):
>             gs = list(g)
>             aggs = dict((ak,sum(d[ak] for d in gs)) for ak in agg_keys)
>             r[k] = aggs
>             if ks:
>                 r[k][ks[0]] = agg(gs,group_keys[1:], agg_keys)
>         return r
>
>     pprint (agg(x1, x2, x3))

Thank you both Steven and Paul for your replies.

@Steven:
> Perhaps you should consider backing up and staring from somewhere else
> with different input data, or changing the requirements. Just a thought.

I think it's not the issue. The data as you noticed i well structured
(as a table for instance) and I don't think I can go better than that.

> I don't think groupby is the tool you want. It groups *consecutive* items
> in sequences:

I was using groupby just like in Paul's code.

@Paul:
OMG. I think this is it! (getting my jaw from the floor...)
The funny part is that I was kind of close to this solution ;). I was
considering the use of recursion for this.

Thank You so much!
-- 
http://mail.python.org/mailman/listinfo/python-list


reStructuredText format a part of a word

2010-06-25 Thread Slafs
Hi there!

Is it possible to format a word using reStructuredText in a way that
only a part of it is formatted (e.g. in bold)?

I would like to do something like this:

my l****ng word

where all the "o"s are in bold but this doesn't work with rst2html

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


Re: reStructuredText format a part of a word

2010-06-25 Thread Slafs
On 25 Cze, 14:06, Thomas Jollans  wrote:
> On 06/25/2010 01:56 PM, Slafs wrote:> Hi there!
>
> > Is it possible to format a word using reStructuredText in a way that
> > only a part of it is formatted (e.g. in bold)?
>
> > I would like to do something like this:
>
> > my l****ng word
>
> l\ ****\ nger word?
>
>
>
> > where all the "o"s are in bold but this doesn't work with rst2html
>
> > Regards
>
>

Yes, thanks, found it too ;]
-- 
http://mail.python.org/mailman/listinfo/python-list