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 5968125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:02:40+00:00 2026-05-22T20:02:40+00:00

In my current django project I have a model that stores very long strings

  • 0

In my current django project I have a model that stores very long strings (can be 5000-10000 or even more characters per DB entry) and then i need to split them when a user is calling the record (it really need to be in one record in the DB). What i need is it to return a list (queryset? depends if in the “SQL” part or getting all the list as is and doing the parsing in the view) of shorter strings (100 – 500 characters per sting in the list i return to the template).

I couldn’t find anywhere a python split command nor example or any kind of answer for that….

I could always count words and append but count words…. but i am sure there has to be some kind of function for that sort of things….

EDIT: thank you everyone, but i guess i wasn’t understood,

Example:

The String: “This is a very long string with many many many many and many more sentences and there is not one character that i can use to split by, just by number of words”

the string is a textField of django model.

i need to split it, lets say every 5 words so i will get:

[‘This is a very long string’,’with many many many many’,’and many more sentences and’,’there is not one character’,’that i can use to’,’split by, just by number’,’ of words’]

The thing is that is almost every programming languages there is split per number of words” kind of utility function but i can’t find one in python.

thanks,
Erez

  • 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-22T20:02:40+00:00Added an answer on May 22, 2026 at 8:02 pm
    >>> s = "This is a very long string with many many many many and many more sentences and there is not one character that i can use to split by, just by number of words"
    >>> l = s.split()
    >>> n = 5
    >>> [' '.join(l[x:x+n]) for x in xrange(0, len(l), n)]
    ['This is a very long',
     'string with many many many',
     'many and many more sentences',
     'and there is not one',
     'character that i can use',
     'to split by, just by',
     'number of words']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have worked a bit with Django and I quite like its project/applications model
My current project is in Rails. Coming from a Symfony (PHP) and Django (Python)
We have a Django project which runs on Google App Engine and used db.UserProperty
In short: How do you specify a BIGINT in Django models? In a current
Current, I've got a stored procedure that has a main goal of doing a
My current development project has two aspects to it. First, there is a public
My current project uses NUnit for unit tests and to drive UATs written with
I have a lot of model classes with ralations between them with a CRUD
I have some django apps which are versioned by app name. appv1 appv2 The
I'm very new to django, about a week into it. I'm making a site

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.