Help me with Stocktake! (systems admin n00b)

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

34 Replies - 1199 Views - Last Post: 28 July 2011 - 05:46 PM Rate Topic: -----

#1 victor.gatto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 25-July 11

Help me with Stocktake! (systems admin n00b)

Posted 25 July 2011 - 05:27 PM

Hi, my name is victor gatto and i am the I.T all rounder in a sydney based auto parts company. We have stocktake coming up, and products we scan from our scanners come up in a text based format on our computers like so :


LOCATION,PART NO.,QUANTITY.



1H013,TS95V-9400-NB,1
1H013,TY05H-6400-NA,3
1H013,TY05H-6400-NA,1
1H013,TB07H-6400-NA,2
1H021,TY06S-6000-NA,10
1H013,TS95V-9400-NB,S
1H013,TY05H-6400-NA,S
1H023,TY05H-6400-NA,S
1H013,TB07H-6400-NA,S
1H011,TY06S-6000-NA,S
1H013,TB07H-6400-NA,M
1H011,TY06S-6000-NA,M


Unfortunately i am a web designer but my weakness is in programming. I know very little about programming and would like to learn more.

My goal by the end of july is to write a script in which the script consolidates and sorts the following text, as consolidating 20,000 items manually its virtually impractical and would consider taking alot of time.


when i run the script, the .txt file should be sorted and look like this , instead of what i showed you before:


1H011,TY06S-6000-NA,2
1H013,TB07H-6400-NA,4
1H013,TS95V-9400-NB,2
1H013,TY05H-6400-NA,5
1H021,TY06S-6000-NA,10
1H023,TY05H-6400-NA,1

The S and M = single and multiple, but at the end of the day, they only = 1.

I hope you understand where i am coming from, and i hope to recieve some support in the future, happy coding :)


Is This A Good Question/Topic? 0
  • +

Replies To: Help me with Stocktake! (systems admin n00b)

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8850
  • View blog
  • Posts: 33,163
  • Joined: 12-June 08

Re: Help me with Stocktake! (systems admin n00b)

Posted 25 July 2011 - 05:30 PM

Just say'n - you could save your txt file as a csv file, open it up in Excel and have your three major pieces of data in a column each... then just use that to sort. It might be easier than trying to learn how to program something to read in a file, put it in some sort of array of objects, sorting that, and then saving it back out.

Edit: this is assuming you don't want a personal programming challenge and instead just want it done.

This post has been edited by modi123_1: 25 July 2011 - 05:31 PM

Was This Post Helpful? 0
  • +
  • -

#3 victor.gatto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 25-July 11

Re: Help me with Stocktake! (systems admin n00b)

Posted 25 July 2011 - 05:35 PM

yeah thats what i did at first, and my boss doesnt like it because he wants to leave it as a .txt file, dont ask -.-
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8850
  • View blog
  • Posts: 33,163
  • Joined: 12-June 08

Re: Help me with Stocktake! (systems admin n00b)

Posted 25 July 2011 - 05:36 PM

You know you just relabel the CSV file back to txt and (assuming you haven't added anything funky) it's just a text file.
Was This Post Helpful? 0
  • +
  • -

#5 victor.gatto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 25-July 11

Re: Help me with Stocktake! (systems admin n00b)

Posted 25 July 2011 - 05:38 PM

but at the same time, i love a challenge, and i might get a pay rise :D
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8850
  • View blog
  • Posts: 33,163
  • Joined: 12-June 08

Re: Help me with Stocktake! (systems admin n00b)

Posted 25 July 2011 - 05:39 PM

Aight.. Just making sure the path of least resistance wasn't plumbed.
Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6021
  • View blog
  • Posts: 23,396
  • Joined: 23-August 08

Re: Help me with Stocktake! (systems admin n00b)

Posted 25 July 2011 - 05:40 PM

Are you looking to do this in C or C++? You're better off using a scripting language like Python.
Was This Post Helpful? 0
  • +
  • -

#8 victor.gatto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 25-July 11

Re: Help me with Stocktake! (systems admin n00b)

Posted 25 July 2011 - 05:43 PM

i understand where you are coming from, but there will be thousands and thousands of S and M's that need to be converted into 1's. I can convert the M's into ones, but i cannot replace some S's simply because they are also in the part no. and thats the last thing i need to change.

thanks for that, i didnt know what language to use, looks like im gonna have to ask some python c0ders.
Was This Post Helpful? 0
  • +
  • -

#9 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6021
  • View blog
  • Posts: 23,396
  • Joined: 23-August 08

Re: Help me with Stocktake! (systems admin n00b)

Posted 25 July 2011 - 05:58 PM

Your first lesson:

#!/usr/bin/env python

theFile="stock.txt"
for line in file(theFile):
   print line.strip()

This post has been edited by JackOfAllTrades: 26 July 2011 - 04:02 AM
Reason for edit:: Removed semicolon

Was This Post Helpful? 0
  • +
  • -

#10 victor.gatto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 25-July 11

Re: Help me with Stocktake! (systems admin n00b)

Posted 25 July 2011 - 06:12 PM

uh , im so noob it actually makes me sick, what does that do and how do i execute the code?

saved as .py? now what? sorry lol.

+ im on windows xp 32 bit, incase if that helps, not mac.
Was This Post Helpful? 0
  • +
  • -

#11 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 758
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Help me with Stocktake! (systems admin n00b)

Posted 25 July 2011 - 08:05 PM

theFile="stock.txt"
for line in file(theFile):
   print line.strip()



Hey boss, I'm adam, one of the resident Python experts. Let's examine the code and try not to overthink it.

Line 1: a variable called theFile refers to stock.txt
Line 2: for each line in theFile
Line 3: print that line with the extra spaces at the beginning and end stripped out


The biggest benefit to python is that it reads like plain english, so learning how to use it is a very trivial task. Admittedly, I oversimplified it a bit... but that's essentially what is going on in the snippet.

This post has been edited by atraub: 25 July 2011 - 09:52 PM

Was This Post Helpful? 0
  • +
  • -

#12 victor.gatto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 25-July 11

Re: Help me with Stocktake! (systems admin n00b)

Posted 25 July 2011 - 08:20 PM

thanks adam, i downloaded python and ran the script, and nothing happened.
Was This Post Helpful? 0
  • +
  • -

#13 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 758
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Help me with Stocktake! (systems admin n00b)

Posted 25 July 2011 - 09:49 PM

did you have a file called stock.txt in the same directory as the script?

Also, which version of Python did you download?

if you downloaded a version that begins with a 3, change your script to this:

#!/usr/bin/env python

theFile="stock.txt"
for line in file(theFile):
   print(line.strip())
input("Press enter to quit")



If it started with a 2, change it to this:
#!/usr/bin/env python

theFile="stock.txt"
for line in file(theFile):
   print line.strip()
raw_input("Press enter to quit")



Also, I don't know how I missed this, but you can get rid of any semicolons ';' from your code; Python does not need those.

This post has been edited by atraub: 25 July 2011 - 09:54 PM

Was This Post Helpful? 0
  • +
  • -

#14 victor.gatto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 25-July 11

Re: Help me with Stocktake! (systems admin n00b)

Posted 25 July 2011 - 10:05 PM

i think we have gone a little off track.
Was This Post Helpful? 0
  • +
  • -

#15 victor.gatto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 25-July 11

Re: Help me with Stocktake! (systems admin n00b)

Posted 25 July 2011 - 10:18 PM

oh adam, i ran the code in python correctly but nothing changed :)

what was meant to happen?
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3