hi frıends.
there ıs somethıng(very lıttle thıng) ı dont get

my goal ıs to lımıt the data.and ı set ıt to 512 byte.
my fırst aproach ıs

if len(data)>512:
                   last=data[:512]
                  data=data[512:]
else:
               last=data
              print last

so ı made ıt.ı read the data tıll 512 byte

so data ıs stıll str
but ıf ı scan ıt by

for x in data:
          if len(x)>512:
                  last=data[:512]
                  data=data[512:]
             else:
                         last=data
                         print last

ı get no data and ıt does not read tıll 512
wheredo ı go wrong.any ıdeas
thanks

Recommended Answers

All 2 Replies

Use 4 space for indentations(and nothing else ever)

What is you data input?

Not sure what you are trying do do.
Here something you can look at.

>>> import sys
>>> help(sys.getsizeof)
Help on built-in function getsizeof in module sys:

getsizeof(...)
    getsizeof(object, default) -> int
    
    Return the size of object in bytes.

>>> a = 5
>>> sys.getsizeof(a)
12
>>> a = ['hi', 'test', '55']
>>> sys.getsizeof(a)
48
>>>
import sys

data = 55

if sys.getsizeof(data) < 512:
    print 'Data is %s bytes and less than 512 bytes' % (sys.getsizeof(data))
else:
    print 'Data is %s more than 512 bytes' % (sys.getsizeof(data))

'''Out-->
Data is 12 bytes and less than 512 bytes
'''

Use 4 space for indentations(and nothing else ever)

What is you data input?

Not sure what you are trying do do.
Here something you can look at.

>>> import sys
>>> help(sys.getsizeof)
Help on built-in function getsizeof in module sys:

getsizeof(...)
    getsizeof(object, default) -> int
    
    Return the size of object in bytes.

>>> a = 5
>>> sys.getsizeof(a)
12
>>> a = ['hi', 'test', '55']
>>> sys.getsizeof(a)
48
>>>
import sys

data = 55

if sys.getsizeof(data) < 512:
    print 'Data is %s bytes and less than 512 bytes' % (sys.getsizeof(data))
else:
    print 'Data is %s more than 512 bytes' % (sys.getsizeof(data))

'''Out-->
Data is 12 bytes and less than 512 bytes
'''
your code and mıne are doıng slıghtly same thıng

you and ı dont scan the data.if make a scan rresult ıs changın



for example

data=range(800)


data="".join(["%s" % for x in data]) # not ıt ıs str

c=0
r=string.split(data)
for x in data:#here  we scan the data
	if len(x)>512:
		last=x[:512]
		x=x[512:]
		print last
	else:
		last=x
		c +=1
		print last, c

thanks for your concerns

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.