Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3965788
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:30:43+00:00 2026-05-20T03:30:43+00:00

How can I implement the below code (ActionScript) in Python? var bytes:ByteArray = new

  • 0

How can I implement the below code (ActionScript) in Python?

var bytes:ByteArray = new ByteArray();
var text:String = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vivamus etc.";

bytes.writeUTFBytes(text); // write the text to the ByteArray
trace("The length of the ByteArray is: " + bytes.length);    // 70
bytes.position = 0; // reset position
while (bytes.bytesAvailable > 0 && (bytes.readUTFBytes(1) != 'a')) {
    //read to letter a or end of bytes
}
if (bytes.position < bytes.bytesAvailable) {
    trace("Found the letter a; position is: " + bytes.position);     // 23
    trace("and the number of bytes available is: " + bytes.bytesAvailable);    // 47
}

I’ve had a look at bytearray and think this code covers the first 4 lines:

text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vivamus etc."
bytes = bytearray(text)
print "The length of the ByteArray is: " + str(len(bytes))

From line 5 onwards I’m not sure of the Python equivalent. For example, I couldn’t find a position method, but can use bytes[i] where i is the position in the bytearray I want to retrieve.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:30:44+00:00Added an answer on May 20, 2026 at 3:30 am
    try:
        index = bytes.index('a')
        print "Found letter a in position", index
        # we substract 1 because the array is 0-indexed.
        print "Bytes available:", len(bytes) - index - 1
    except ValueError:
        print "Letter a not found"
    

    This solution is much clearer and human-readable than the ActionScript code, and it even follows the EAFP python philosophy.

    x[x.index('a')] == 'a', this means that x.index('a') will return the index of the first occurrence of a (and will raise a ValueError if there is no a in the bytearray).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can i implement the below code with jQuery/AJAX timer,(I have created 2 URL
how can i implement setInterval or setTimeout on click of button. my code bellow
Can someone please tell me how I can implement the following line of pseudo-code.
I would like to implement a bidirectional fifo. The code below is functioning but
Can someone convert below code to ASP format? <?php $data = ' [ {
in the code below i want to implement the floyd algorithm,the user enter some
Is there any better way to implement the below code <form id=myform onsubmit=return saveUserData('firstname','lastname');
I see below code in this link : An elegant way to implement INotifyPropertyChanged
I want to implement VideoRecording function. I have the below code,but it throws me
can someone tell if the code below would work fine? class CriticalSection{ int iProcessId,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.