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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:39:45+00:00 2026-06-05T08:39:45+00:00

I have a function that I use on two different machine one a Mac

  • 0

I have a function that I use on two different machine one a Mac running Python version 2.6 and the other is a Lenovo running version 3.2.The function writes data to a file and is called from with in a loop. When using Python 3.2 it works as expected and I get output such as below

25.0    25.0    25.0    0
25.0    25.0    75.0    0
25.0    25.0    125.0   0
25.0    25.0    175.0   0
25.0    25.0    225.0   0
25.0    75.0    25.0    0
25.0    75.0    75.0    0
25.0    75.0    125.0   0
25.0    75.0    175.0   0
25.0    75.0    225.0   0

When I run it on the machine running version 2.6 I get this

175.0   25.0    75.0    2
175.0   25.0    125.0   0
25.0    25.0    25.0    0   Should be first line
175.0   25.0    175.0   0
25.0    25.0    75.0    0   Should be second line
175.0   25.0    225.0   0   
25.0    25.0    125.0   1
175.0   75.0    25.0    0
25.0    25.0    175.0   1
175.0   75.0    75.0    2

Here is the code

def filesave(Xc,Yc,Zc,S): 
 Xc = str(Xc)
 Yc = str(Yc)
 Zc = str(Zc)
 Xs = str(S)
 #Ms = str(Ma)   
 w = open("Myout.txt.","a+")
 w.write(Xc)
 w.write('\t')
 w.write(Yc)
 w.write('\t')
 w.write(Zc)
 w.write('\t')
 w.write(Xs)
 w.write('\n')
 w.close()
 return()

Is there some difference between the two versions that is causing the difference? Thanks!

EDIT

Rest of Code

def cell_centers():
 read_file(F)
 dx = dy = dz= float(input('Please enter a value for dr:'))    #length of cell side 
 N  = int(input('Please enter a value for N:')) #N^3 Number of cells to be created
 Xc = zeros(N)       #array creation
 Yc = zeros(N)
 Zc = zeros(N)
 x1=0
 y1=0
 z1=0
 county = 0
 countz = 0

 for i in range(N):          #for loops to define cell centers
    Xc[i] = dx/2 +x1                  
    xmin = Xc[i]-dx/2
    xmax = Xc[i]+dx/2
    x1+=dx                   #increments x1 positions by dx
    for j in range(N):
      Yc[j] = dy/2 +y1
      ymin = Yc[j]-dy/2
      ymax = Yc[j]+dy/2
      county+=1
      if county==N:          #if else statement resets y1 to zero
        y1=0
        county=0
      else:
        y1+=dy
      for k in range(N):
         Zc[k] = dz/2 +z1
         countz+=1
         zmin = Zc[k]-dz/2
         zmax = Zc[k]+dz/2
         if countz==N:
          z1=0   
          countz=0
         else:
          z1+=dz
         counter(Xc[i],Yc[j],Zc[k],N,xmin,xmax,ymin,ymax,zmin,zmax,*read_file(F))

 return()        



def counter(Xc,Yc,Zc,N,xmin,xmax,ymin,ymax,zmin,zmax,Xa,Ya,Za):
 Cellcount = zeros(1)   
 S = (((xmin <= Xa) & (Xa <= xmax))& #count what is in specific range
     ((ymin <= Ya) & (Ya <= ymax))&
     ((zmin <= Za) & (Za <= zmax))).sum()

 for l in range(1):
   Cellcount[l]= S
 filesave(Xc,Yc,Zc,S)
 return()
  • 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-06-05T08:39:46+00:00Added an answer on June 5, 2026 at 8:39 am

    I am going to go out on the limb and say the difference you are observing is due to the changed division between version 2.x and 3.x. (it looks like there’s a lot of dividing going on, and I can’t tell what type the numbers are, integer or float)

    In 2.x you would get integer truncation when doing division with integers. This doesn’t happen in v 3.x

    Python 2

    In [267]: 5 / 2
    Out[267]: 2
    

    Python 3:

    In [1]: 5 / 2
    Out[1]: 2.5
    

    Your code does a lot of division.

    If you still want to old integer division behavior, you can use // with Python 3:

    Python 3:

    In [2]: 5 // 2
    Out[2]: 2
    

    Changing the Division Operator explains this in detail.

    What’s New In Python 3.0 goes over the big changes from v 2 to 3

    If you want the new division behavior in Python 2.2+, you can use the from __future__ import division directive (Thanks @Jeff for reminding me).

    Python 2:

    In [1]: 5 / 2
    Out[1]: 2
    
    In [2]: from __future__ import division
    
    In [3]: 5 / 2
    Out[3]: 2.5
    

    UPDATE:

    Finally, please consider the potential problem of division as a cause (so perhaps the lines aren’t out of order, but the results are different due to the division making it only appear that way). Is that possible? Also notice that the 4th column (the 3.x output) has all zeros .. that’s not present in the 2.x output and further points toward possible problems with the computation of results — so in fact the results are different and not out of order.

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

Sidebar

Related Questions

I have two classes that I use to access two different tables in my
I have two different div elements on two different webpages that use two different
I have a function that needs to return two strings. I've considered two different
I have a form with two different UserControls - one that contains a Telerik
I have two function that do the exact same thing in two different ways.
Here, I have two different version of my code. The first one is a
I have a function that use setInterval() method to watch css propertie change('cause in
I have a function that I use on index.php page and I would like
I have a function that I use quite frequently, which allows me to write
I have a function that returns a NSUrl, and i want to use it

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.