Convert integer to fixed length binary string

2009-06-11 Thread casebash
Hi,

I know the bin function converts an int into a binary string.
Unfortunately, I need to know the length of the binary string when it
is being read in and len(bin(x)) depends on x. Is there any way to
limit it to 4 bytes?

Thanks for your assistance,

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


Re: Convert integer to fixed length binary string

2009-06-11 Thread casebash
Sorry, I didn't quite make it clear. The issue isn't about limiting
the length (as I won't be using integers bigger than this). The
problem is that sometimes the output is shorter.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert integer to fixed length binary string

2009-06-11 Thread casebash
Thanks, this is what I needed

On Jun 11, 9:40 pm, Ulrich Eckhardt  wrote:
> casebash wrote:
> > I know the bin function converts an int into a binary string.
>
> Binary string sounds ambiguous. Firstly, everything is binary. Secondly,
> strings are byte strings or Unicode strings. In any case, I'm not 100% sure
> what you mean - giving an example of input and output would help!
>
> > Unfortunately, I need to know the length of the binary string when it
> > is being read in and len(bin(x)) depends on x. Is there any way to
> > limit it to 4 bytes?
>
> If you need a piece of four bytes which contain a number in a packed format
> similar to the one used in memory, using bin(x) is the wrong way. Instead,
> take a look at the struct module:
>
>   import struct
>   struct.pack('=L', 255)
>
> Alternatively, also the array module might help.
>
> Uli
>
> --
> Sator Laser GmbH
> Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Mutable Strings - Any libraries that offer this?

2009-07-20 Thread casebash
Hi,

I have searched this list and found out that Python doesn't have a
mutable string class (it had an inefficient one, but this was removed
in 3.0). Are there any libraries outside the core that offer this?

Thanks,

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


Re: Mutable Strings - Any libraries that offer this?

2009-07-22 Thread casebash
Thanks all for your advice. I'm not actually going to use the mutable
string right at the moment, but I thought I might in the future and I
was just curious if it existed. I suppose a list of characters is
close enough for most purposes.

On Jul 22, 10:28 am, greg  wrote:
> Ben Finney wrote:
> > My point was rather meant to imply that
> > subclassing the built-in (immutable)stringtypes was the best way to
> > usefully get all their functionality
>
> However, it would be difficult to do that without changing
> all C code that deals with strings, including that in extension
> modules.
>
> That's because the existingstringtype stores the characters
> in thestringobject itself. Amutablevariant would have to
> contain a pointer to a resizable memory block, and therefore
> couldn't be used as a drop-in replacement by existing C
> code that expects astring.
>
> --
> Greg

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


Nice copy in interactive terminal

2009-08-12 Thread casebash
Hello fellow Python Users,

I've been wondering for a while if there exists an interactive
terminal which has nice copy feature (ie. I can copy code without
getting the >>> in front of every line).

Thanks,

Chris

PS. apologies if I am posting this in the wrong group. I am unsure of
the exact scope of this group.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nice copy in interactive terminal

2009-08-14 Thread casebash
I mainly develop on Linux these days, but if I ever end up doing
anything on windows I'll make sure to look at that.

On Aug 13, 6:56 pm, "Elias Fotinis \(eliasf\)" 
wrote:
> "casebash" wrote:
> > I've been wondering for a while if there exists an interactive
> > terminal which has nice copy feature (ie. I can copy code without
> > getting the >>> in front of every line).
>
> It would help if we knew what platform you're interested in -- your
> User-Agent is G2/1.0, but I don't know what that is.  :o)
>
> On Windows, PythonWin can copy from the interactive window without the
> prompts.

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


Determining the metaclass

2009-08-29 Thread casebash
Hi all,

I cannot determine if a class is an instance of a particular
metaclass. Here is my best attempt

>>> class tmp(type):
... pass
...
>>> def c(metaclass=tmp):
... pass
...
>>> isinstance(c, tmp)
False
>>> isinstance(c.__class__, tmp)
False

Can anyone explain why this fails?

Thanks very much,

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


Why does this group have so much spam?

2009-08-30 Thread casebash
So much of it could be removed even by simple keyword filtering.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nice copy in interactive terminal

2009-08-30 Thread casebash
I managed to get some more answers here:

http://stackoverflow.com/questions/1352886/nice-copying-from-python-interpreter

On Aug 14, 5:05 pm, casebash  wrote:
> I mainly develop on Linux these days, but if I ever end up doing
> anything on windows I'll make sure to look at that.
>
> On Aug 13, 6:56 pm, "Elias Fotinis \(eliasf\)" 
> wrote:
>
> > "casebash" wrote:
> > > I've been wondering for a while if there exists an interactive
> > > terminal which has nice copy feature (ie. I can copy code without
> > > getting the >>> in front of every line).
>
> > It would help if we knew what platform you're interested in -- your
> > User-Agent is G2/1.0, but I don't know what that is.  :o)
>
> > On Windows, PythonWin can copy from the interactive window without the
> > prompts.
>
>

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


Re: Determining the metaclass

2009-09-01 Thread casebash
Thanks, I am silly


>
> > I cannot determine if a class is an instance of a particular
> > metaclass. Here is my best attempt
>
> > >>> class tmp(type):
>
> > ...     pass
> > ...>>> def c(metaclass=tmp):
>
> > ...     pass
> > ...>>> isinstance(c, tmp)
> > False
> > >>> isinstance(c.__class__, tmp)
>
> > False
>
> > Can anyone explain why this fails?
>
> You're gonna kick yourself.
>
> It's because you used "def" and not "class" to define c.  If you'd
> used "class" then then first test would have worked.
>
> Carl Banks

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