# Writedlm works in REPL but not in a script

**URL:** https://discourse.julialang.org/t/writedlm-works-in-repl-but-not-in-a-script/4061
**Category:** General Usage
**Created:** [June 2, 2017, 3:37pm UTC](https://discourse.julialang.org/t/writedlm-works-in-repl-but-not-in-a-script/4061 "2017-06-02T15:37:23Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![phillefjonk](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@phillefjonk](https://discourse.julialang.org/u/phillefjonk)
#### Post date: [June 2, 2017, 3:37pm UTC](https://discourse.julialang.org/t/writedlm-works-in-repl-but-not-in-a-script/4061/1 "2017-06-02T15:37:23Z")

</div>

Why does the following work in REPL

```julia
julia> A = rand(3,3)
3×3 Array{Float64,2}:
 0.967353 0.187512 0.296005
 0.616798 0.620456 0.076472
 0.0759498 0.105753 0.41141 

julia> writedlm("data2.txt", A)

julia>

```

But not in a script

```julia
A= rand(3,3)
file = open("data2.txt")
writedlm(file,A)
close(file)

```

I get the error:  
ERROR: LoadError: ArgumentError: write failed, IOStream is not writeable

when I run the script in a terminal

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [June 2, 2017, 3:53pm UTC](https://discourse.julialang.org/t/writedlm-works-in-repl-but-not-in-a-script/4061/2 "2017-06-02T15:53:20Z")

</div>

You are not writing the same code what’s why they behave differently.

The error message should be pretty clear. The `IOStream` (`file`) isn’t writable. You need to open the file for writing so do `open(..., "w")`
